From fabfe1e68e3b2925508ab09939b9ac8139973429 Mon Sep 17 00:00:00 2001 From: Ben Eater Date: Fri, 4 Oct 2024 22:42:35 -0700 Subject: [PATCH 1/5] Add LCDPRINT and LCDCMD instructions --- README.md | 11 +++-- init.s | 3 ++ lcd.s | 137 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ msbasic.s | 1 + token.s | 4 ++ 5 files changed, 153 insertions(+), 3 deletions(-) create mode 100644 lcd.s diff --git a/README.md b/README.md index 48ba9ff..cef7f69 100644 --- a/README.md +++ b/README.md @@ -7,8 +7,9 @@ But if you're following along with earlier videos, the "code" link below will ta | | Video | Code | |--------------------------------|----------------------------------------------------------|--------------------| | ![Video thumbnail][thumbnail1] | [Running MSBASIC on my breadboard 6502 computer][video1] | [a15c8e0][commit1] | -| ![Video thumbnail][thumbnail2] | [How input buffering works][video2] | [54ef9ac][commit2] | -| ![Video thumbnail][thumbnail3] | [RS232 flow control][video3] | [master][commit3] | +| ![Video thumbnail][thumbnail2] | [How input buffering works][video2] | [54ef9ac][commit2] | +| ![Video thumbnail][thumbnail2] | [RS232 flow control][video3] | [c21542e][commit3] | +| ![Video thumbnail][thumbnail4] | [Hacking Microsoft BASIC][video4] | [master][commit4] | [thumbnail1]: https://i.ytimg.com/vi/XlbPnihCM0E/mqdefault.jpg [video1]: https://youtu.be/XlbPnihCM0E @@ -22,7 +23,11 @@ But if you're following along with earlier videos, the "code" link below will ta [thumbnail3]: https://i.ytimg.com/vi/LuKMVXWD7FY/mqdefault.jpg [video3]: https://youtu.be/LuKMVXWD7FY -[commit3]: https://github.com/beneater/msbasic/tree/master +[commit3]: https://github.com/beneater/msbasic/tree/c21542e724b3da45ba3790405c2cf85e77bc1ad4 + +[thumbnail4]: https://i.ytimg.com/vi/gOwi2p1pzVM/mqdefault.jpg +[video4]: https://youtu.be/gOwi2p1pzVM +[commit4]: https://github.com/beneater/msbasic/tree/master Below is the original README: diff --git a/init.s b/init.s index 702938a..9c1d08f 100644 --- a/init.s +++ b/init.s @@ -123,6 +123,9 @@ COLD_START: lda #WIDTH2 sta Z18 .endif + .ifdef EATER + jsr LCDINIT + .endif .endif ; All non-CONFIG_SMALL versions of BASIC have diff --git a/lcd.s b/lcd.s new file mode 100644 index 0000000..cf6edc6 --- /dev/null +++ b/lcd.s @@ -0,0 +1,137 @@ +.segment "CODE" +.ifdef EATER +PORTB = $6000 +DDRB = $6002 +E = %01000000 +RW = %00100000 +RS = %00010000 + +lcd_wait: + pha + lda #%11110000 ; LCD data is input + sta DDRB +lcdbusy: + lda #RW + sta PORTB + lda #(RW | E) + sta PORTB + lda PORTB ; Read high nibble + pha ; and put on stack since it has the busy flag + lda #RW + sta PORTB + lda #(RW | E) + sta PORTB + lda PORTB ; Read low nibble + pla ; Get high nibble off stack + and #%00001000 + bne lcdbusy + + lda #RW + sta PORTB + lda #%11111111 ; LCD data is output + sta DDRB + pla + rts + +LCDINIT: + lda #$ff ; Set all pins on port B to output + sta DDRB + + lda #%00000011 ; Set 8-bit mode + sta PORTB + ora #E + sta PORTB + and #%00001111 + sta PORTB + + lda #%00000011 ; Set 8-bit mode + sta PORTB + ora #E + sta PORTB + and #%00001111 + sta PORTB + + lda #%00000011 ; Set 8-bit mode + sta PORTB + ora #E + sta PORTB + and #%00001111 + sta PORTB + + ; Okay, now we're really in 8-bit mode. + ; Command to get to 4-bit mode ought to work now + lda #%00000010 ; Set 4-bit mode + sta PORTB + ora #E + sta PORTB + and #%00001111 + sta PORTB + + lda #%00101000 ; Set 4-bit mode; 2-line display; 5x8 font + jsr lcd_instruction + lda #%00001110 ; Display on; cursor on; blink off + jsr lcd_instruction + lda #%00000110 ; Increment and shift cursor; don't shift display + jsr lcd_instruction + lda #%00000001 ; Clear display + jsr lcd_instruction + rts + + +LCDCMD: + jsr GETBYT + txa +lcd_instruction: + jsr lcd_wait + pha + lsr + lsr + lsr + lsr ; Send high 4 bits + sta PORTB + ora #E ; Set E bit to send instruction + sta PORTB + eor #E ; Clear E bit + sta PORTB + pla + and #%00001111 ; Send low 4 bits + sta PORTB + ora #E ; Set E bit to send instruction + sta PORTB + eor #E ; Clear E bit + sta PORTB + rts + +LCDPRINT: +; jsr GETBYT +; txa + jsr GETSTR + ldy #$00 + lda (INDEX),y + jsr lcd_print_char + rts + +lcd_print_char: + jsr lcd_wait + pha + lsr + lsr + lsr + lsr ; Send high 4 bits + ora #RS ; Set RS + sta PORTB + ora #E ; Set E bit to send instruction + sta PORTB + eor #E ; Clear E bit + sta PORTB + pla + and #%00001111 ; Send low 4 bits + ora #RS ; Set RS + sta PORTB + ora #E ; Set E bit to send instruction + sta PORTB + eor #E ; Clear E bit + sta PORTB + rts + +.endif diff --git a/msbasic.s b/msbasic.s index 7ef660f..a7d5f69 100644 --- a/msbasic.s +++ b/msbasic.s @@ -33,3 +33,4 @@ .include "trig.s" .include "init.s" .include "extra.s" +.include "lcd.s" diff --git a/token.s b/token.s index 3c6cfd7..c6bf0d6 100644 --- a/token.s +++ b/token.s @@ -78,6 +78,10 @@ keyword_rts "PRT", PRT .endif keyword_rts "NEW", NEW +.ifdef EATER + keyword_rts "LCDCMD", LCDCMD + keyword_rts "LCDPRINT", LCDPRINT +.endif count_tokens From 6134abc14b4f4bc384e3cb39abd3bffec464c3d3 Mon Sep 17 00:00:00 2001 From: Jai Stoud Date: Thu, 10 Oct 2024 23:35:57 +0200 Subject: [PATCH 2/5] Added make script for MS Windows --- make.cmd | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 make.cmd diff --git a/make.cmd b/make.cmd new file mode 100644 index 0000000..01ac658 --- /dev/null +++ b/make.cmd @@ -0,0 +1,10 @@ +@echo off +if not exist tmp ( + mkdir tmp +) + +for %%i in (cbmbasic1 cbmbasic2 kbdbasic osi kb9 applesoft microtan aim65 sym1 eater) do ( + echo %%i + C:\CC65\bin\ca65 -D %%i msbasic.s -o tmp\%%i.o + C:\CC65\bin\ld65 -C %%i.cfg tmp\%%i.o -o tmp\%%i.bin -Ln tmp\%%i.lbl +) From 8ed010b15ddbd6c9eb2dd6a51c9a0753b8e9af3b Mon Sep 17 00:00:00 2001 From: Jai Stoud Date: Fri, 11 Oct 2024 11:04:52 +0200 Subject: [PATCH 3/5] Modified LCDPRINT to use formular editor of msbasic. --- lcd.s | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lcd.s b/lcd.s index cf6edc6..9cbcd4f 100644 --- a/lcd.s +++ b/lcd.s @@ -103,12 +103,24 @@ lcd_instruction: rts LCDPRINT: -; jsr GETBYT -; txa - jsr GETSTR - ldy #$00 - lda (INDEX),y - jsr lcd_print_char + jsr FRMEVL ; Evaluate formular + bit VALTYP ; Is it a string? + bmi lcd_print_string ; Yes + jsr FOUT ; Format floating point output + jsr STRLIT ; Build string descriptor +lcd_print_string: + jsr FREFAC ; Returns temp pointer to string + tax ; Put count to counter + ldy #0 + inx ; Move one ahead +lcd_print_next: + dex + beq lcd_print_end ; All done + lda (INDEX),y ; Load char of string + jsr lcd_print_char ; Output to lcd + iny + bne lcd_print_next ; Go on with next char +lcd_print_end: rts lcd_print_char: From cbac29b75984aa3affb75d671b08fd5622c78186 Mon Sep 17 00:00:00 2001 From: Jai Stoud Date: Sat, 19 Oct 2024 17:12:45 +0200 Subject: [PATCH 4/5] Forward integration from Ben Eaters repo. --- lcd.s | 23 ++--------------------- 1 file changed, 2 insertions(+), 21 deletions(-) diff --git a/lcd.s b/lcd.s index 9cbcd4f..7ad3b64 100644 --- a/lcd.s +++ b/lcd.s @@ -103,27 +103,8 @@ lcd_instruction: rts LCDPRINT: - jsr FRMEVL ; Evaluate formular - bit VALTYP ; Is it a string? - bmi lcd_print_string ; Yes - jsr FOUT ; Format floating point output - jsr STRLIT ; Build string descriptor -lcd_print_string: - jsr FREFAC ; Returns temp pointer to string - tax ; Put count to counter - ldy #0 - inx ; Move one ahead -lcd_print_next: - dex - beq lcd_print_end ; All done - lda (INDEX),y ; Load char of string - jsr lcd_print_char ; Output to lcd - iny - bne lcd_print_next ; Go on with next char -lcd_print_end: - rts - -lcd_print_char: + jsr GETBYT + txa jsr lcd_wait pha lsr From ceafdbced5ea55d7edf90a0d8045a7d9c07e7f60 Mon Sep 17 00:00:00 2001 From: Jai Stoud Date: Sat, 19 Oct 2024 17:29:39 +0200 Subject: [PATCH 5/5] Added LCDPRINT by using the formular evaluator. --- lcd.s | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/lcd.s b/lcd.s index 7ad3b64..9cbcd4f 100644 --- a/lcd.s +++ b/lcd.s @@ -103,8 +103,27 @@ lcd_instruction: rts LCDPRINT: - jsr GETBYT - txa + jsr FRMEVL ; Evaluate formular + bit VALTYP ; Is it a string? + bmi lcd_print_string ; Yes + jsr FOUT ; Format floating point output + jsr STRLIT ; Build string descriptor +lcd_print_string: + jsr FREFAC ; Returns temp pointer to string + tax ; Put count to counter + ldy #0 + inx ; Move one ahead +lcd_print_next: + dex + beq lcd_print_end ; All done + lda (INDEX),y ; Load char of string + jsr lcd_print_char ; Output to lcd + iny + bne lcd_print_next ; Go on with next char +lcd_print_end: + rts + +lcd_print_char: jsr lcd_wait pha lsr