- Started Applesoft API

- Basic command name parsing and matching
- Error handling for undefined calls and syntax errors
This commit is contained in:
Quinn Dunki 2014-09-09 20:34:14 -07:00
parent 5dc871c64e
commit 663f7278f9
5 changed files with 179 additions and 4 deletions

View File

@ -11,6 +11,7 @@
70868EE119BD178F00E4B4CB /* zeropage.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = zeropage.s; sourceTree = "<group>"; };
709E88E319AC0A5F0069DB55 /* views.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = views.s; sourceTree = "<group>"; };
709E88E419AC0DC20069DB55 /* unit_test.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = unit_test.s; sourceTree = "<group>"; };
70A3A2C219BFE2C3006A2EC4 /* applesoft.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = applesoft.s; sourceTree = "<group>"; };
70B2272519A9685200702171 /* utility.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = utility.s; sourceTree = "<group>"; };
70D435B119A0137F001BFD9B /* Makefile */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.make; path = Makefile; sourceTree = "<group>"; };
70D435B219A013AF001BFD9B /* gui.s */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.asm; path = gui.s; sourceTree = "<group>"; };
@ -36,6 +37,7 @@
70F1DB5619A6B02900321637 /* painting.s */,
70868EE019BD150C00E4B4CB /* rects.s */,
709E88E319AC0A5F0069DB55 /* views.s */,
70A3A2C219BFE2C3006A2EC4 /* applesoft.s */,
70D435B219A013AF001BFD9B /* gui.s */,
709E88E419AC0DC20069DB55 /* unit_test.s */,
70D435B419A0141F001BFD9B /* guidemo.s */,

172
applesoft.s Normal file
View File

@ -0,0 +1,172 @@
;
; applesoft.s
; Applesoft API via the & extension point
;
; Created by Quinn Dunki on 8/15/14.
; Copyright (c) 2014 One Girl, One Laptop Productions. All rights reserved.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Applesoft ROM entry points and constants
;
WG_AMPVECTOR = $03f5
CHRGET = $00b1
ERROR = $d412
ERR_UNDEFINEDFUNC = 224
ERR_SYNTAX = 16
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGInitApplesoft
; Sets up Applesoft API
;
WGInitApplesoft:
pha
lda #$4c ; Patch in our jump vector for &
sta WG_AMPVECTOR
lda #<WGAmpersand
sta WG_AMPVECTOR+1
lda #>WGAmpersand
sta WG_AMPVECTOR+2
pla
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand
; The entry point from Applesoft. Applesoft text pointer
; will be positioned two after the '&', and accumulator will
; contain first character after the '&'
; Side effects: Clobbers S0
;
WGAmpersand:
sta SCRATCH0
SAVE_AXY
ldy #0
ldx SCRATCH0
WGAmpersand_parseLoop:
txa
beq WGAmpersand_parseMatchStart ; Check for end-of-statement
cmp #':'
beq WGAmpersand_parseMatchStart
sta WGAmpersandCommandBuffer,y
jsr CHRGET
tax
iny
cpy #14
bne WGAmpersand_parseLoop
WGAmpersand_parseMatchStart:
ldy #0
ldx #0 ; Command buffer now contains our API call
phx ; We stash the current command number on the stack
WGAmpersand_parseMatchLoop:
lda WGAmpersandCommandBuffer,y
beq WGAmpersand_parseMatchFound ; Made it to the end
cmp WGAmpersandCommandTable,x
bne WGAmpersand_parseMatchNext ; Not this one
iny
inx
bra WGAmpersand_parseMatchLoop
WGAmpersand_parseMatchNext:
pla ; Advance index to next commmand in table
inc
pha
asl
asl
asl
asl
tax
cpx #WGAmpersandCommandTableEnd-WGAmpersandCommandTable
beq WGAmpersand_parseFail ; Hit the end of the table
ldy #0
bra WGAmpersand_parseMatchLoop
WGAmpersand_parseMatchFound:
pla ; This is now the matching command number
inc
asl
asl
asl
asl
tay
lda WGAmpersandCommandTable-2,y ; Prepare an indirect JSR to our command
sta WGAmpersand_commandJSR+1
lda WGAmpersandCommandTable-1,y
sta WGAmpersand_commandJSR+2
; Self modifying code:
WGAmpersand_commandJSR:
jsr WGAmpersand_done ; Address here overwritten with command
bra WGAmpersand_done
WGAmpersand_parseFail:
pla ; We left command number on the stack while matching
ldx #ERR_UNDEFINEDFUNC
jsr ERROR
WGAmpersand_done:
RESTORE_AXY
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Ampersand API entry points
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_view
; Create a view
;
WGAmpersand_VIEW:
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; WGAmpersand_desk
; Render the desktop
;
WGAmpersand_DESK:
jsr WGDesktop
rts
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Applesoft API state
;
WGAmpersandCommandBuffer:
.byte 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
; Jump table for ampersand commands.
; Each row is 16 bytes (14 for name, 2 for address)
WGAmpersandCommandTable:
.byte "VIEW",0,0,0,0,0,0,0,0,0,0
.addr WGAmpersand_VIEW
.byte "DESK",0,0,0,0,0,0,0,0,0,0
.addr WGAmpersand_DESK
WGAmpersandCommandTableEnd:

7
gui.s
View File

@ -1,6 +1,6 @@
;
; gui.s
; AssemblyTest
; Top level management routines
;
; Created by Quinn Dunki on 8/15/14.
; Copyright (c) 2014 One Girl, One Laptop Productions. All rights reserved.
@ -21,6 +21,7 @@
main:
jsr WGInit
jsr WG80
rts
;jmp tortureTestPrint
;jmp tortureTestRects
@ -265,8 +266,7 @@ testCallback:
WGInit:
pha
lda #0
sta WG_FOCUSVIEW
jsr WGInitApplesoft
pla
rts
@ -315,6 +315,7 @@ read80ColSwitch_40:
.include "painting.s"
.include "rects.s"
.include "views.s"
.include "applesoft.s"
.include "unit_test.s"
.include "memory.s"

Binary file not shown.

View File

@ -27,7 +27,7 @@ GUI_MAIN = $4000
main:
jmp GUI_MAIN
;rts