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..9cbcd4f --- /dev/null +++ b/lcd.s @@ -0,0 +1,149 @@ +.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 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 + 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/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 +) 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