From f5c4af0201af451853d7daf014543a69da1904cc Mon Sep 17 00:00:00 2001 From: Quinn Dunki Date: Thu, 11 Sep 2014 14:04:30 -0700 Subject: [PATCH] - Parameter parsing and command table working for AppleSoft API - String and integer vector parameters supported --- applesoft.s | 203 ++++++++++++++++++++++++++++++++++++++++++++++------ guidemo | Bin 0 -> 3 bytes guidemo.dsk | Bin 143360 -> 143360 bytes guidemo.o | Bin 0 -> 389 bytes views.s | 2 +- 5 files changed, 183 insertions(+), 22 deletions(-) create mode 100644 guidemo create mode 100644 guidemo.o diff --git a/applesoft.s b/applesoft.s index 90420c9..ff9fa09 100644 --- a/applesoft.s +++ b/applesoft.s @@ -11,12 +11,21 @@ ; Applesoft ROM entry points and constants ; WG_AMPVECTOR = $03f5 -CHRGET = $00b1 -ERROR = $d412 +CHRGET = $00b1 ; Advances text point and gets character in A +CHRGOT = $00b7 ; Returns character at text pointer in A +SYNCHR = $dec0 ; Validates current character is what's in A +TXTPTR = $00b8 ; (and $b9) ; Current location in BASIC listing +ERROR = $d412 ; Reports error in X +CHKCOM = $debe ; Validates current character is a ',', then gets it +GETBYT = $e6f8 ; Gets an integer at text pointer, stores in X +GETNUM = $e746 ; Gets an 8-bit, stores it X, skips past a comma ERR_UNDEFINEDFUNC = 224 - ERR_SYNTAX = 16 +ERR_TOOLONG = 176 + +MAXCMDLEN = 14 + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; WGInitApplesoft @@ -46,15 +55,16 @@ WGInitApplesoft: WGAmpersand: sta SCRATCH0 SAVE_AXY + SAVE_ZPP ldy #0 ldx SCRATCH0 WGAmpersand_parseLoop: txa - beq WGAmpersand_parseMatchStart ; Check for end-of-statement - cmp #':' - beq WGAmpersand_parseMatchStart + beq WGAmpersand_parseFail ; Check for end-of-statement (CHRGET handles : and EOL) + cmp #'(' + beq WGAmpersand_matchStart sta WGAmpersandCommandBuffer,y @@ -62,25 +72,33 @@ WGAmpersand_parseLoop: tax iny - cpy #14 + cpy #MAXCMDLEN bne WGAmpersand_parseLoop -WGAmpersand_parseMatchStart: +WGAmpersand_parseFail: + ldx #ERR_SYNTAX + jsr ERROR + bra WGAmpersand_done + +WGAmpersand_matchStart: + lda #0 + sta WGAmpersandCommandBuffer,y ; Null terminate the buffer for matching + ldy #0 ldx #0 ; Command buffer now contains our API call phx ; We stash the current command number on the stack -WGAmpersand_parseMatchLoop: +WGAmpersand_matchLoop: lda WGAmpersandCommandBuffer,y - beq WGAmpersand_parseMatchFound ; Made it to the end + beq WGAmpersand_matchFound ; Got one! cmp WGAmpersandCommandTable,x - bne WGAmpersand_parseMatchNext ; Not this one + bne WGAmpersand_matchNext ; Not this one iny inx - bra WGAmpersand_parseMatchLoop + bra WGAmpersand_matchLoop -WGAmpersand_parseMatchNext: +WGAmpersand_matchNext: pla ; Advance index to next commmand in table inc pha @@ -91,12 +109,12 @@ WGAmpersand_parseMatchNext: tax cpx #WGAmpersandCommandTableEnd-WGAmpersandCommandTable - beq WGAmpersand_parseFail ; Hit the end of the table + beq WGAmpersand_matchFail ; Hit the end of the table ldy #0 - bra WGAmpersand_parseMatchLoop + bra WGAmpersand_matchLoop -WGAmpersand_parseMatchFound: +WGAmpersand_matchFound: pla ; This is now the matching command number inc asl @@ -105,26 +123,131 @@ WGAmpersand_parseMatchFound: asl tay lda WGAmpersandCommandTable-2,y ; Prepare an indirect JSR to our command - sta WGAmpersand_commandJSR+1 + sta WGAmpersand_commandJSR+1 ; Self-modifying code! lda WGAmpersandCommandTable-1,y sta WGAmpersand_commandJSR+2 - ; Self modifying code: + ; Self-modifying code! WGAmpersand_commandJSR: jsr WGAmpersand_done ; Address here overwritten with command bra WGAmpersand_done -WGAmpersand_parseFail: +WGAmpersand_matchFail: pla ; We left command number on the stack while matching ldx #ERR_UNDEFINEDFUNC jsr ERROR WGAmpersand_done: + RESTORE_ZPP RESTORE_AXY rts +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; WGAmpersandIntArguments +; Buffers integer arguments for the current command in PARAMx +; TXTPTR: Start of argument list (after opening parenthesis) +; OUT PARAMx : The arguments +WGAmpersandIntArguments: + SAVE_AXY + + ldy #0 + phy ; Can't rely on Applesoft routines to be register-safe + + lda #'(' + jsr SYNCHR ; Expect opening parenthesis + +WGAmpersandIntArguments_loop: + jsr GETBYT + txa + ply + sta PARAM0,y + phy + + jsr CHRGOT + cmp #')' ; All done! + beq WGAmpersandIntArguments_cleanup + jsr CHKCOM ; Verify parameter separator + + ply + iny + phy + cpy #4 ; Check for too many arguments + bne WGAmpersandIntArguments_loop + +WGAmpersandIntArguments_fail: + ldx #ERR_TOOLONG + jsr ERROR + bra WGAmpersandIntArguments_done + +WGAmpersandIntArguments_cleanup: + jsr CHRGET ; Consume closing parenthesis + +WGAmpersandIntArguments_done: + ply + RESTORE_AXY + rts + + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +; WGAmpersandStrArgument +; Buffers a string argument for the current command in PARAM0/1 +; TXTPTR: Start of argument list (after opening parenthesis) +; OUT PARAM0/1 : The argument +WGAmpersandStrArguments: + SAVE_AXY + + ldy #0 + phy ; Can't rely on Applesoft routines to be register-safe + + lda #'(' + jsr SYNCHR ; Expect opening parenthesis + +WGAmpersandStrArguments_loop: + jsr CHRGOT + beq WGAmpersandStrArguments_tooShort + cmp #')' + beq WGAmpersandStrArguments_cleanup + + ply + sta WGAmpersandCommandBuffer,y + iny + phy + cpy #WGAmpersandCommandBufferEnd-WGAmpersandCommandBuffer + beq WGAmpersandStrArguments_tooLong + + jsr CHRGET + bra WGAmpersandStrArguments_loop + +WGAmpersandStrArguments_tooLong: + ldx #ERR_TOOLONG + jsr ERROR + bra WGAmpersandStrArguments_done + +WGAmpersandStrArguments_tooShort: + ldx #ERR_SYNTAX + jsr ERROR + bra WGAmpersandStrArguments_done + +WGAmpersandStrArguments_cleanup: + jsr CHRGET ; Consume closing parenthesis + +WGAmpersandStrArguments_done: + ply ; Null-terminate result + lda #0 + sta WGAmpersandCommandBuffer,y + + lda #WGAmpersandCommandBuffer + sta PARAM1 + + RESTORE_AXY + rts + + ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; Ampersand API entry points @@ -133,14 +256,49 @@ WGAmpersand_done: ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; WGAmpersand_view +; WGAmpersand_VIEW ; Create a view ; WGAmpersand_VIEW: + jsr WGAmpersandStrArguments + +; lda WGAmpersandCommandBuffer +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+1 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+2 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+3 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+4 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+5 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+6 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+7 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+8 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+9 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+10 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+11 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+12 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+13 +; jsr PRBYTE +; lda WGAmpersandCommandBuffer+14 +; jsr PRBYTE + + jsr WGCreateView + jsr WGPaintView rts ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -; WGAmpersand_desk +; WGAmpersand_DESK ; Render the desktop ; WGAmpersand_DESK: @@ -155,7 +313,10 @@ WGAmpersand_DESK: ; WGAmpersandCommandBuffer: +.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 .byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 +WGAmpersandCommandBufferEnd: +.byte 0 ; Make sure this last byte is always kept as a terminator ; Jump table for ampersand commands. diff --git a/guidemo b/guidemo new file mode 100644 index 0000000000000000000000000000000000000000..076a4aa600057232ed12eaff7c943f6bd1c0f46d GIT binary patch literal 3 KcmeZaZ~y=SCjgBA literal 0 HcmV?d00001 diff --git a/guidemo.dsk b/guidemo.dsk index 36f93eb1ffe69cdccea1c3827ade05a416cd22da..a1218e203a4bae81dec8ed49ae9ddd1174b65724 100644 GIT binary patch delta 2265 zcmaJ?du&r>6u<4Zu47{qhR|Nz`n9mF?SM_jV;PDozA0!|IC5^h}#z=yXWS;Nd+jcd|{o{L_ z@0{N`=XcI`KmN9nzimtnR?cp!ZLDONyG)2K#7`^Nnf{)~G}Y>>sj!1C&i-0yebc{P zFh~KRoUGm~-PM*Kc%@z1^5|yiRc*<5B)OpAz@;0_KJ!X%7ZmP`+ul223~PduI=$}8 zy{4+tI|1pAIDh}w<(&b+alR=aUf!4$DML*f2_}+30}0yWvIz#RjXNXQ{Gr&P($iN=YFAFMI!V3m>7B8 z6C%I4L!wSk#4AJ9j_3RvHa_KL@?Wo?Tyjecnf8)ipJYaatqLPUgB@!#^h>*-YnqML z!@$6RdAAFqjgXVKO*TT*2?Lr+Lte!J;@Y9w#}fumqTG`(dJ+|w(181P3gY)OCQkAAa-WVY}IE`A$R7Ig;~ zhVvXfxEJY<8JHlFg;dQY7jE?4ET7jpr*@9Pf*Z;T}@o&=jej+pAw zOQG$L$3U<|%)6W6vZbXg)(rfjgoRG?scf8)^(IAHhM_hC7ZzAfu>6U5c_2=4lzFJ5 zW$0*y>ZnC^)S^1V2_3cM9O0HaY5^|iM`?^W6CuHFnpl`-hH=Xkq^28-oaOIn4K$n& zC>(2r{~)b3NL6qQF4W!R8{iQR;b|75KRhzIg8~mu9pqtC2~!e zx2Id7OE=R+dL_tJ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>&UBa>JwAAKvjymZme}BZ1}T;5RzOsY`|! z@mqnV+Yu%0i4J>|2~YH650~xE%-_p5k`eTfP3T&$ZwyniG1eSyyaCFll!iF zxLZ!baI-G1%}ri2LSDO#PwoT_R|`Ohg@JqQeku`X5iLf!8NL9+MQ zjvs*A_BCa(10XI=*y*&0(k2+yY}KfdGQuEPkXS*o|ABZpAVD*f{!c^u(9j{>P={`) zLpOvI8tTXz!Y#Gak+;M5@O^xo>4|W@rfg*Bw_3?9Y~l{_8SzIwQ7DyVM`E3j+y$tB z0{3=-^~w1Ble;KM&-Y%KEV(02>moU7Csc~4h$?x&tj2zrh?rH&M2WgkT%mMAqp8q@ zav0R=XvC!)f#?Yr*X2ThfaZ7Bql6`P3=-wBqmaios)Vc~ly#W00w;s;K`R6bg0Uro zfDM^mMYF86rXRAfXYW9E1PkpDdU+!6yDTUN5r-j>R>v4W1W^Bf!52|Qt=xh-&#P;1?uI)6S-<6N)uwiW863MW_e@VR|egu$NNM_18ymO{oF~6ZU3z zJ_F;Yq>fRI+z=wn(;)C@C0>}=pnB=kERPSiRF<{SXVpE>EZc@M@hj#r>!tBI@_4dg VY;DPEle{{4j*7mU8cvzSzW_qVW{&^> diff --git a/guidemo.o b/guidemo.o new file mode 100644 index 0000000000000000000000000000000000000000..01073200109d97cf7c7d443b3ff465220bbaa480 GIT binary patch literal 389 zcmWHo%1h*CU|@&Qzw8G#r?fM`Z2%><>HfpjBKyamb!DFp#0 zCT53&caJY%Wn@~lfj{I7P?}pDD9+9dk!4`?k>vxaV{ib`96%-rg9Jb{$SE*3$T=`J z$f+QQfYk7S*%0--NNkX?F!lUMYyl*;Ae0TFgcx|^;~fJ6d|ZuO{XF91InzrsQ&MyD z^@@3t6U|H&!i@9`jrEK<+(SL%eH}ghSaK6H^H}wYGpkZroc&!~*@FCC977zLoq~f| zKn#v3*C77@M|W2izfd0^wy1z$$1qnm*9cb+mmv1w5XYd9&;S-sKhF?$AOCQW0So{; CiZ7r5 literal 0 HcmV?d00001 diff --git a/views.s b/views.s index be78438..02e0a29 100644 --- a/views.s +++ b/views.s @@ -26,7 +26,7 @@ WGCreateView: SAVE_AXY SAVE_ZPS - + ldy #0 jsr scanHex8 pha