<commit_before>{{
KS0107/08 Monochrome LCD Framebuffer Driver
─────────────────────────────────────────────────
Version: 1.0
Copyright (c) 2013 LameStation LLC
See end of file for terms of use.

Authors: <NAME>
─────────────────────────────────────────────────
}}



CON
'' These indicate which pins connect to what. If developing your own prototype,
'' you can change the value of LCDstart to change the location of the LCD
'' pinout.
''
  LCDstart = 0
  LCDend = LCDstart + 11

'' The pins on a KS0108 LCD are as follows.
''
'' * **D/I** - Indicates whether next command is data or instruction. 
'' * **R/W** - Controls whether reading from or writing to the LCD. On the LameStation, this pin is wired to ground.
'' * **EN** - This pin controls whether data is being sent. It remains off while data is prepared then toggled on to deliver.
'' * **DB0-7** - These 8 bits are how data is delivered to the LCD, whether it is pixel data, address values, or otherwise.
'' * **CSA, CSB** - Each KS0108 controller only actually handles 64x64 on-screen pixels, so a 128x64 LCD
''           requires two of these chips in order to function. To handle this, the control signals are demultiplexed
''           to one or both of the two chips, depending on which one is selected. In most cases, the Propeller is only
''           talking to one of these chips at a time, because most time is spending sending screen data. The rare case
''
  DI = LCDstart + 0
  EN = LCDstart + 1
  DBstart = LCDstart + 2
  DBend = LCDstart + 9
  CSA = LCDstart + 10
  CSB = LCDstart + 11

'' I have this constant so that the frame rate can be limited;
'' however, in practice, I set it to some high value like 300
'' so that the screen will refresh as fast as possible.
''
  FRAMERATE = 200
  
'' For differences in LCD chipsets, set byte period to:
''
'' - KS0108 - 220
'' - SBN0064G - 300
''
'' Some LCDs just can't be driven as fast.
''
  BYTEPERIOD = 220
    
    
  
    ' screensize constants
    SCREEN_W = 128
    SCREEN_H = 64
    BITSPERPIXEL = 2

    SCREEN_H_BYTES = SCREEN_H / 8
    SCREENSIZE_BYTES = SCREEN_W * SCREEN_H_BYTES * BITSPERPIXEL
    TOTALBUFFER_BYTES = SCREENSIZE_BYTES
    
    SCREENLOCK = 0

VAR

    word    screenframe
    word    screenpointer
    word    framepointer
    word    screen1[TOTALBUFFER_BYTES/2]
    word    screen2[TOTALBUFFER_BYTES/2]
    
OBJ

    pst : "LameSerial"

PUB Start

    cognew(@lcd_entry, @framepointer)
    SwitchFrame
    return @screenpointer


PUB SwitchFrame | x
'' LameLCD, when initialized, sets up a double-buffered drawing surface
'' to work with. It then switches back and forth between drawing to a
'' buffer and outputting the contents of that buffer to the screen.
'' This allows the screen to be redrawn at predictable intervals and
'' eliminates screen tearing.
''
'' Whenever you wish to update the screen, simply call this function and it
'' switch to the other frame. This command has no parameters.

    repeat until not lockset(SCREENLOCK) 

    if screenframe    
        screenframe := 0
        framepointer := @screen1
        screenpointer := @screen2<commit_msg>Removed LameSerial object from LameLCD<commit_after>{{
KS0107/08 Monochrome LCD Framebuffer Driver
─────────────────────────────────────────────────
Version: 1.0
Copyright (c) 2013 LameStation LLC
See end of file for terms of use.

Authors: <NAME>
─────────────────────────────────────────────────
}}



CON
'' These indicate which pins connect to what. If developing your own prototype,
'' you can change the value of LCDstart to change the location of the LCD
'' pinout.
''
  LCDstart = 0
  LCDend = LCDstart + 11

'' The pins on a KS0108 LCD are as follows.
''
'' * **D/I** - Indicates whether next command is data or instruction. 
'' * **R/W** - Controls whether reading from or writing to the LCD. On the LameStation, this pin is wired to ground.
'' * **EN** - This pin controls whether data is being sent. It remains off while data is prepared then toggled on to deliver.
'' * **DB0-7** - These 8 bits are how data is delivered to the LCD, whether it is pixel data, address values, or otherwise.
'' * **CSA, CSB** - Each KS0108 controller only actually handles 64x64 on-screen pixels, so a 128x64 LCD
''           requires two of these chips in order to function. To handle this, the control signals are demultiplexed
''           to one or both of the two chips, depending on which one is selected. In most cases, the Propeller is only
''           talking to one of these chips at a time, because most time is spending sending screen data. The rare case
''
  DI = LCDstart + 0
  EN = LCDstart + 1
  DBstart = LCDstart + 2
  DBend = LCDstart + 9
  CSA = LCDstart + 10
  CSB = LCDstart + 11

'' I have this constant so that the frame rate can be limited;
'' however, in practice, I set it to some high value like 300
'' so that the screen will refresh as fast as possible.
''
  FRAMERATE = 200
  
'' For differences in LCD chipsets, set byte period to:
''
'' - KS0108 - 220
'' - SBN0064G - 300
''
'' Some LCDs just can't be driven as fast.
''
  BYTEPERIOD = 220
    
    
  
    ' screensize constants
    SCREEN_W = 128
    SCREEN_H = 64
    BITSPERPIXEL = 2

    SCREEN_H_BYTES = SCREEN_H / 8
    SCREENSIZE_BYTES = SCREEN_W * SCREEN_H_BYTES * BITSPERPIXEL
    TOTALBUFFER_BYTES = SCREENSIZE_BYTES
    
    SCREENLOCK = 0

VAR

    word    screenframe
    word    screenpointer
    word    framepointer
    word    screen1[TOTALBUFFER_BYTES/2]
    word    screen2[TOTALBUFFER_BYTES/2]

PUB Start

    cognew(@lcd_entry, @framepointer)
    SwitchFrame
    return @screenpointer


PUB SwitchFrame | x
'' LameLCD, when initialized, sets up a double-buffered drawing surface
'' to work with. It then switches back and forth between drawing to a
'' buffer and outputting the contents of that buffer to the screen.
'' This allows the screen to be redrawn at predictable intervals and
'' eliminates screen tearing.
''
'' Whenever you wish to update the screen, simply call this function and it
'' switch to the other frame. This command has no parameters.

    repeat until not lockset(SCREENLOCK) 

    if screenframe    
        screenframe := 0
        framepointer := @screen1
        screenpointer := @screen2
{'fraction_non_alphanumeric': 0.10019236934915036, 'fraction_numerical': 0.025969862135299775, 'mean_word_length': 3.212694125590817, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5950649', 'n_tokens_mistral': 2093, 'n_tokens_neox': 1818, 'n_words': 824}