{-----------------------------------------------------------------------+ | | | Apple-1 mockup | | For testing original Microchess code on v6502 | | | +-----------------------------------------------------------------------} gcl0x { Zero page usage: $30-$31 Pos $32-$33 PrintChar $34-$3b WozMon variables } _i=$3c {2 bytes} _j=$3e {2 bytes} _k=$3a {1 bytes, share with wozmon YSAV} {-----------------------------------------------------------------------+ | ROM type check | +-----------------------------------------------------------------------} { This code runs once and is then reused as the input buffer for wozmon } *=\userCode \romType, \romTypeValue_ROMv4- {Version check >= ROMv4, see Docs/GT1-files.txt} [if<0 do _frameCount _vPCH: {https://forum.gigatron.io/viewtopic.php?f=4&t=130} loop] &_Setup call {Continue in page 8} {-----------------------------------------------------------------------+ | Setup | +-----------------------------------------------------------------------} *=$8a0 _Setup=* {Continuation of program start} { Setup video indirection table such that WozMon can be at $7F00/$FF00 } \videoTable Pos= {First GCL variable at $30, later becomes Pos} 120 {7^127} [do 127^ {Loop over 7..126 range} Pos: 0loop] {Next in range} &_PrintChar PrintChar= {Prepare for vCPU calls} [def #$d0 #$e5 #$f4 #$e5 #$f2 #$a0 #$ca #$e5 #$ee #$ee {Peter Jenn} #$e9 #$ee #$e7 #$f3 #$a7 #$a0 #$cd #$e9 #$e3 #$f2 {ings' Micr} #$ef #$e3 #$e8 #$e5 #$f3 #$f3 #$a8 #$c3 #$a9 #$b1 {ochess(C)1} #$b9 #$b7 #$b6 #$a0 #$e2 #$e5 #$ee #$ec #$ef #$ae {976 benlo.} #$e3 #$ef #$ed #0 ] s= {com} [do s, if<>0 {Print message} PrintChar! 0loop] [do \frameCount, 15& [if=0 {4 Hz cursor redraw rate} \frameCount, 48& {Flash at 1 Hz with 75% duty cycle} [if=0 $a0 else $c0] {Select space or '@'} PrintChar! Pos=] {Display cursor and move back} \serialRaw, \k. 128& {Key ready?} if<>0loop] {Loop until ready} $a0 PrintChar! Pos= {Overwrite '@' with a space} \k, $60- [if>=0 $40+ \k.] {Map to upper case, and DEL to rubout} \k, 10^ [if=0 13 \k.] {Map LF to CR} else {A<>0 for echo} \k. PrintChar! ] pop {Restore v6502 PC} loop] {Back to wozmon} {-----------------------------------------------------------------------+ | Character output with automatic scrolling | +-----------------------------------------------------------------------} _PrintChar=* [ {Minimalistic terminal output, with bit 7 set by WozMon} %-2= {Park character in stack area} \SYS_VDrawBits_134 _sysFn= {Prepare SYS calls} $800 \sysArgs0: {Green on black} %-2 {Get character back} $8d^ [if<>0 {Test for CR...} 0 0] {...or line wrap} [if=0 {-------------------------------------------------------------------+ | Newline | +-------------------------------------------------------------------} {Clear new line first} $100 Pos. Pos {Go to start of next line} \sysArgs4: {Set screen position} \sysArgs2. {Set all-zero output pattern} [do 134!! {SYS call to draw 8 pixels vertically} <\sysArgs4++ {Step 1 pixel right} \sysArgs4, 160^ {Test for end of line} if<>0loop] {Then scroll up by modifying videoTable} $01ee _i= {Last entry in video table} [do _i, 119- [if<0 127+ else 7+] _i. {Rotate by 8 in 7..126 range} _i 2- _i= {Move to previous entry in video table} $fe^ if<>0loop] {Until all done} ] %-2 $a0- {WozMon sends ASCII with bit 7 set} [if>=0 {If printable} {-------------------------------------------------------------------+ | PrintChar | +-------------------------------------------------------------------} { Draw ASCII character (32..127) on screen in 5x8 pixels } { and advance cursor position } 50- {Map ASCII code to offset in font table} [if<0 50+ _i= \font32up {ASCII 32..81} else _i= \font82up] {ASCII 82..127} _j= _i 2<< _i+ {Multiply char code by 5} _j+ _j= {Add to page address to reach bitmap data} Pos \sysArgs4: {Screen position for character} %-2= {Remember this position} 6+ Pos= {Advance by 6 pixels} 5 [do _i= {Draw character as 5 vertical bit slices} _j 0? \sysArgs2. {Get bit slice as byte from ROM table} 134!! {SYS call to draw 8 pixels vertically} <_j++ <\sysArgs4++ {Advance to next byte} _i 1- if>0loop] {Looping} %-2 {Return position for backspace} ] ret ] {-----------------------------------------------------------------------+ | WozMon | +-----------------------------------------------------------------------} *=$ff00 { Original ZP usage is 24.2B, but that's taken by Gigatron } _XAML=$34 _XAML_MINUS1=$33 _XAMH=$35 _STL=$36 _STL_MINUS1=$35 _STH=$37 _L=$38 _L_MINUS1=$37 _H=$39 _YSAV=$3A _MODE=$3B { Patches with respect to original are marked [Gigatron] } _IN=$200 _KBD=$D010 _KBDCR=$D011 _DSP=$D012 _DSPCR=$D013 _RESET=* #_CLD_ { Clear decimal arithmetic mode. } #_CLI_ #_LDYIM_ #$7F { Mask for DSP data direction register. } #_STY_ ##_DSP #_LDAIM_ #$A7 { KBD and DSP control register mask. } #_STA_ ##_KBDCR #_STA_ ##_DSPCR _NOTCR=* #_CMPIM_ #$DF { "<-"? } #_BEQ_ #@_BACKSPACE { Yes. } #_CMPIM_ #$9B { ESC? } #_BEQ_ #@_ESCAPE { Yes. } #_INY_ { Advance text index. } #_BPL_ #@_NEXTCHAR { Auto ESC if > 127. } _ESCAPE=* #_LDAIM_ #$DC { "\". } #_JSR_ ##_ECHO { Output it. } _GETLINE=* #_LDAIM_ #$8D { CR. } #_JSR_ ##_ECHO { Output it. } #_LDYIM_ #$01 { Initiallize text index. } _BACKSPACE=* #_DEY_ { Back up text index. } #_BMI_ #@_GETLINE { Beyond start of line, reinitialize. } _NEXTCHAR=* #_LDAIM_ #$00 { [Gigatron] A=0 to read keyboard. } #_BRK_ { [Gigatron] Transfer to vCPU for input. } #_ORAIM_ #$80 { [Gigatron] B7 should be '1'. } #_BIT_ ##_KBD { [Gigatron] Was: LDA } #_STAAY_ ##_IN { Add to text buffer. } #_JSR_ ##_ECHO { Display character. } #_CMPIM_ #$8D { CR? } #_BNE_ #@_NOTCR { No. } #_LDYIM_ #$FF { Reset text index. } #_LDAIM_ #$00 { For XAM mode. } #_TAX_ { 0->X. } _SETSTOR=* #_ASLA_ { Leaves $7B if setting STOR mode. } _SETMODE=* #_STAZ_ #_MODE { $00 = XAM, $7B= STOR,$AE= BLOK XAM } _BLSKIP=* #_INY_ { Advance text index. } _NEXTITEM=* #_LDAAY_ ##_IN { Get character. } #_CMPIM_ #$8D { CR? } #_BEQ_ #@_GETLINE { Yes, done this line. } #_CMPIM_ #$AE { "."? } #_BCC_ #@_BLSKIP { Skip delimiter. } #_BEQ_ #@_SETMODE { Yes, BLOCK XAM mode. } #_CMPIM_ #$BA { ":"? } #_BEQ_ #@_SETSTOR { Yes, set STOR mode. } #_CMPIM_ #$D2 { "R"? } #_BEQ_ #@_RUN { Yes, run user program. } #_STXZ_ #_L { $00->L. } #_STXZ_ #_H { and H. } #_STYZ_ #_YSAV { Save Y for comparison. } _NEXTHEX=* #_LDAAY_ ##_IN { Get character for hex test. } #_EORIM_ #$B0 { Map digits to $0-9. } #_CMPIM_ #$0A { Digit? } #_BCC_ #@_DIG { Yes. } #_ADCIM_ #$88 { Map letter "A"-"F" to $FA-FF. } #_CMPIM_ #$FA { Hex letter? } #_BCC_ #@_NOTHEX { No, character not hex. } _DIG=* #_ASLA_ { } #_ASLA_ { Hex digit to MSD of A. } #_ASLA_ { } #_ASLA_ { } #_LDXIM_ #$04 { Shift count. } _HEXSHIFT=* #_ASLA_ { Hex digit left, MSB to carry. } #_ROLZ_ #_L { Rotate into LSD. } #_ROLZ_ #_H { Rotate into MSD's. } #_DEX_ { Done 4 shifts? } #_BNE_ #@_HEXSHIFT { No, loop. } #_INY_ { Advance text index. } #_BNE_ #@_NEXTHEX { Always taken. Check next character for hex.} _NOTHEX=* #_CPYZ_ #_YSAV { Check if L, H empty (no hex digits). } #_BEQ_ #@_ESCAPE { Yes, generate ESC sequence. } #_BITZ_ #_MODE { Test MODE byte. } #_BVC_ #@_NOTSTOR { B6 = 0 for STOR, 1 for XAM and BLOCK XAM} #_LDAZ_ #_L { LSD's of hex data. } #_STAIX_ #_STL { Store at current 'store index'. } #_INCZ_ #_STL { Increment store index. } #_BNE_ #@_NEXTITEM { Get next item. (no carry). } #_INCZ_ #_STH { Add carry to 'store index' high order. } _TONEXTITEM=* #_JMP_ ##_NEXTITEM { Get next command item. } _RUN=* #_JMI_ ##_XAML { Run at current XAM index. } _NOTSTOR=* #_BMI_ #@_XAMNEXT { B7 = 0 for XAM, 1 for BLOCK XAM. } #_LDXIM_ #$02 { Byte count. } _SETADR=* #_LDAZX_ #_L_MINUS1 { Copy hex data to } #_STAZX_ #_STL_MINUS1 { 'store index'. } #_STAZX_ #_XAML_MINUS1 { And to 'XAM index'. } #_DEX_ { Next of 2 bytes. } #_BNE_ #@_SETADR { Loop unless X = 0. } _NXTPRNT=* #_BNE_ #@_PRDATA { NE means no address to print. } #_LDAIM_ #$8D { CR. } #_JSR_ ##_ECHO { Output it. } #_LDAZ_ #_XAMH { 'Examine index' high-order byte. } #_JSR_ ##_PRBYTE { Output it in hex format. } #_LDAZ_ #_XAML { Low-order 'examine index' byte. } #_JSR_ ##_PRBYTE { Output it in hex format. } #_LDAIM_ #$BA { ":". } #_JSR_ ##_ECHO { Output it. } _PRDATA=* #_LDAIM_ #$04 { [Gigatron] 4 pixels wide blank. } #_JSR_ ##_BLANK { [Gigatron] Output it. } #_LDAIX_ #_XAML { Get data byte at 'examine index'. } #_JSR_ ##_PRBYTE { Output it in hex format. } _XAMNEXT=* #_STXZ_ #_MODE { 0->MODE (XAM mode). } #_LDAZ_ #_XAML { } #_CMPZ_ #_L { Compare 'examine index' to hex data. } #_LDAZ_ #_XAMH { } #_SBCZ_ #_H { } #_BCS_ #@_TONEXTITEM { Not less, so no more data to output. } #_INCZ_ #_XAML { } #_BNE_ #@_MOD8CHK { Increment 'examine index'. } #_INCZ_ #_XAMH { } _MOD8CHK=* #_LDAZ_ #_XAML { Check low-order 'examine index' byte } #_ANDIM_ #$07 { For MOD 8= 0 } #_BPL_ #@_NXTPRNT { Always taken. } _PRBYTE=* #_PHA_ { Save A for LSD. } #_LSRA_ { } #_LSRA_ { } #_LSRA_ { MSD to LSD position. } #_LSRA_ { } #_JSR_ ##_PRHEX { Output hex digit. } #_PLA_ { Restore A. } _PRHEX=* #_ANDIM_ #$0F { Mask LSD for hex print. } #_ORAIM_ #$B0 { Add "0". } #_CMPIM_ #$BA { Digit? } #_BCC_ #@_ECHO { Yes, output it. } #_ADCIM_ #$06 { Add offset for letter. } _CHAROUT=* _ECHO=* #_PHA_ { [Gigatron] } #_BRK_ { [Gigatron] Transfer to vCPU for display.} #_PLA_ { [Gigatron] } #_RTS_ { [Gigatron] Return. } _BLANK=* #_CLC_ { [Gigatron] Advance few pixels so BLOCK } #_ADCZ_ #