diff --git a/online/online.asm b/online/online.asm index 3c1c21a..f96b515 100644 --- a/online/online.asm +++ b/online/online.asm @@ -44,6 +44,7 @@ fbits = $be56 ; Parameter bits found vslot = $be61 vdriv = $be62 gosystem = $be70 +xreturn = $be9e ; Guaranteed RTS instruction sonline = $bec6 ; BASIC.SYSTEM ONLINE parameter table sunitnum = $bec7 sbufadr = $bec8 @@ -78,7 +79,10 @@ cout = $fded ; Application stuff: +cptr = $0c ; Code pointer +dptr = $0e ; Data pointer buffer = inbuf +codelen = (_CodeEndAddress - _CodeBeginAddress) .org $2000 @@ -91,51 +95,98 @@ install: clc adc #$01 cld - bmi @6502 + bpl @not6502 + +@6502: + jsr printz + asciizh "ERR: MUST HAVE ENHANCED //E, //C, OR IIGS" + rts + +; Get address from BASIC.SYSTEM: +@not6502: + lda #1 + jsr getbufr + bcc @gotmem + +@nomem: + jsr printz + asciizh "UNABLE TO ALLOCATE MEMORY" + rts + +@gotmem: + sta cptr+1 + stz cptr ; Move code to destination address: -; TODO: Get address from BASIC.SYSTEM and move there, relocate code ldy #0 : lda _CodeStartAddress,y - sta _CodeBeginAddress,y + sta (cptr),y iny - cpy #(_CodeEndAddress-_CodeBeginAddress) bne :- +; Patch code for new location - ASSUMES 1 PAGE ONLY! + ldy #0 +@copy: + lda (cptr),y + jsr ilen ; calculate instruction length + tax + cpx #3 + bne :+ + iny ; Skip instruction + dex + iny ; Skip low byte + dex + lda (cptr),y + cmp #>_CodeBeginAddress + bne :+ + lda cptr+1 + sta (cptr),y +: iny ; Skip rest of instruction + dex + bne :- + cpy #codelen + bcc @copy + ; Setup BASIC.SYSTEM hooks: ; 1. Save EXTRNCMD lda extrncmd+2 - sta nextcmd+1 + ldy #entry + lda cptr+1 sta extrncmd+2 lda #online + jsr xreturn + tsx + lda $100,x ; Retrieve address from stack sta xtrnaddr+1 stz xcnum lda #buffer sta sbufadr+1 -; Note: if we have a specific unit, this is not zero terminated -- fake it! +; Note: if we have a specific unit, the buffer will not be zero terminated -- fake it! stz buffer+16 lda #$C5 ; ONLINE system command jsr gosystem @@ -292,6 +344,8 @@ printspc: lda #' '|$80 jmp cout +_CodeEndAddress: + msgERR: asciizh "ERR=$" @@ -301,5 +355,3 @@ cmdlen = *-cmdtable nextcmd: .word 0 -_CodeEndAddress: -