diff --git a/Apple2/Clock.Driver.asm b/Apple2/Clock.Driver.asm new file mode 100644 index 0000000..fc84c59 --- /dev/null +++ b/Apple2/Clock.Driver.asm @@ -0,0 +1,140 @@ +; Copyright Terence J. Boldt (c)2024 +; Use of this source code is governed by an MIT +; license that can be found in the LICENSE file. + +; This file contains the source for the clock +; driver for the Apple2-IO-RPi + +EnableWriteLang = $C08B +DisableWriteLang = $C082 + +ProdosJump = $BF06 +ProdosClockCode = $BF07 +ProdosMachineId = $BF98 + +PrintChar = $FDED +PrintHex = $FDE3 +PrintByte = $FDDA + +GetTimeCommand = $03 + +.org $2000 +; Find Apple2-IO-RPi card + ldx #$06 + ldy #$09 +CheckIdBytes: + lda $C700,y ; !! Self modifying code + cmp IdBytes,y + bne NextCard + dey + bne CheckIdBytes + jmp FoundCard +NextCard: + dec CheckIdBytes+2 + ldy #$09 + dex + bne CheckIdBytes +CardNotFound: + ldy #$00 +PrintCardNotFound: + lda TextCardNotFound,y + beq Failed + ora #$80 + jsr PrintChar + iny + bne PrintCardNotFound +Failed: + rts +FoundCard: + ldy #$00 +PrintCardFound: + lda TextCardFound,y + beq PrintCardNumber + ora #$80 + jsr PrintChar + iny + bne PrintCardFound +PrintCardNumber: + inx + txa + jsr PrintHex + lda #$8D + jsr PrintChar + + +; Change driver code to point to the card + txa + ora #$C0 + sta GetByte+2 + sta SendByte+2 + +; Change destination to be ProDOS clock code location + lda ProdosClockCode + sta DriverDestination+1 + lda ProdosClockCode+1 + sta DriverDestination+2 + +; Changing RTS to JMP enables clock driver + lda #$4C ; jump instruction + sta ProdosJump + +; Enable writing to language card RAM +; by triggering switch twice + lda EnableWriteLang + lda EnableWriteLang + +; write driver code to language card RAM + ldy #$00 +WriteDriver: + lda Driver,y +DriverDestination: + sta $D742,y ; !! this address gets modified above + iny + cpy #EndDriver-Driver+2 + bne WriteDriver + +; Disable writing to language card RAM + lda DisableWriteLang + +; Update ProDOS Machine ID to mark clock as enabled + lda ProdosMachineId + ora #$01 + sta ProdosMachineId + + ldy #$00 +PrintFinished: + lda TextDriverInstalled,y + beq Finished + ora #$80 + jsr PrintChar + iny + bne PrintFinished +Finished: + rts + +IdBytes: +.byte $E0,$20,$E0,$00,$E0,$03,$E0,$3C,$A9,$3F + +TextCardFound: +.byte "Found Apple2-IO-RPi in slot ",$00 + +TextCardNotFound: +.byte "Apple2-IO-RPi not found",$8D,$00 + +TextDriverInstalled: +.byte "Apple2-IO-RPi Clock driver version 0001",$8D,$00 + +Driver: + lda #GetTimeCommand +SendByte: + jsr $C749 ; !! address gets modified on installation + ldy #$00 +getTimeByte: +GetByte: + jsr $C743 ; !! address gets modified on installation + sta $bf90,y + iny + cpy #$04 + bne getTimeByte +EndDriver: + rts diff --git a/Apple2/CommandFirmware.asm b/Apple2/CommandFirmware.asm index 3ec96b2..865fbce 100644 --- a/Apple2/CommandFirmware.asm +++ b/Apple2/CommandFirmware.asm @@ -2,8 +2,9 @@ ; Use of this source code is governed by an MIT ; license that can be found in the LICENSE file. -; This file contains the source for the firmware -; that was formerly used to act as a pseudo-shell +; This file formerly contained the source for the +; firmware that had a pseudo command prompt +; but is now empty except required common bytes ;ProDOS Zero Page Command = $42 ;ProDOS Command @@ -32,141 +33,41 @@ LoadFileCommand = $06 SaveFileCommand = $07 MenuCommand = $08 -InputString = $fd67 -PrintChar = $fded -Keyboard = $c000 -ClearKeyboard = $c010 -Wait = $fca8 - .org SLOT*$100 + $C000 ;ID bytes for booting and drive detection - cpx #$20 ;ID bytes for ProDOS and the - cpx #$00 ; Apple Autostart ROM + cpx #$20 ;ID bytes for ProDOS + cpx #$00 ; cpx #$03 ; + cpx #$3C ;ID byte for Autostart ROM - ldx #SLOT*$10 - stx $2b - stx Unit - -;force EPROM to second page on boot lda #$3f ;set all flags high and page 3 of EPROM for menu + jmp PageJump + +;The following bytes must exist in this location for Pascal communications +;as they are standard pointers for entry points +.byte CommInit&$00FF ;low byte of rts for init of Pascal comms +.byte $43 ; low byte of read for Pascal comms +.byte $49 ; low byte of write for Pascal comms +.byte $4F ; low byte of rts for status of Pascal comms + +CommInit: + lda #$0f ; set all flags high and page 0 for comm driver + sta OutputFlags + ldx #$00 ; set error code to 0 for success + rts + PageJump: sta OutputFlags - jmp Start ;this jump is only called if coming in from PageJump with A=$2f + jmp Start ;this jump is only called if coming in from PageJump with A=$0f ;entry points for ProDOS DriverEntry: lda #$0f ;set all flags high and page 0 of EPROM sta OutputFlags + jmp Start ; this is never called as the EPROM page changes +;load first two blocks and execute to boot Start: - jsr $c300 ;enable 80 columns - lda #$05 ;execute command - jsr SendByte - ldy #$00 -sendHelp: - lda HelpCommand,y - beq endSendHelp - jsr SendByte - iny - bne sendHelp -endSendHelp: - lda #$00 - jsr SendByte - jsr DumpOutput - - lda $33 - pha - lda #$a4 - sta $33 -GetCommand: - jsr InputString - lda $0200 - cmp #$8d ;skip when return found - beq GetCommand - jsr SendCommand - clc - bcc GetCommand - -SendCommand: - bit ClearKeyboard - lda #$05 ;send command 5 = exec - jsr SendByte - ldy #$00 -getInput: - lda $0200,y - cmp #$8d - beq sendNullTerminator - and #$7f - jsr SendByte - iny - bne getInput -sendNullTerminator: - lda #$00 - jsr SendByte -DumpOutput: - jsr GetByte - bcs skipOutput - cmp #$00 - beq endOutput - jsr PrintChar -skipOutput: - bit Keyboard ;check for keypress - bpl DumpOutput ;keep dumping output if no keypress - lda Keyboard ;send keypress to RPi - jsr PrintChar - and #$7f - jsr SendByte - bit ClearKeyboard - clc - bcc DumpOutput -endOutput: - rts - -HelpCommand: - .byte "a2help",$00 - -SendByte: - bit InputFlags - bvs SendByte - sta OutputByte -.if HW_TYPE = 0 - lda #$1e ; set bit 0 low to indicate write started - sta OutputFlags -finishWrite: - bit InputFlags - bvc finishWrite - lda #$1f - sta OutputFlags -.endif - rts - -GetByte: -.if HW_TYPE = 0 - ldx #$1d ;set read flag low - stx OutputFlags -.endif -waitRead: - bit InputFlags - bpl readByte - bit Keyboard ;keypress will abort waiting to read - bpl waitRead -.if HW_TYPE = 0 - lda #$1f ;set all flags high and exit - sta OutputFlags -.endif - sec ;failure - rts -readByte: - lda InputByte -.if HW_TYPE = 0 - ldx #$1f ;set all flags high - stx OutputFlags -finishRead: - bit InputFlags - bpl finishRead -.endif - clc ;success end: rts @@ -175,5 +76,6 @@ end: .endrepeat .byte 0,0 ;0000 blocks = check status -.byte 7 ;bit set(0=status 1=read 2=write) unset(3=format, 4/5=number of volumes, 6=interruptable, 7=removable) +.byte 23 ;bit set(0=status 1=read 2=write) unset(3=format, 4/5=number of volumes, 6=interruptable, 7=removable) .byte DriverEntry&$00FF ;low byte of entry + diff --git a/Apple2/DriveFirmware.asm b/Apple2/DriveFirmware.asm index a37f571..9f714d8 100644 --- a/Apple2/DriveFirmware.asm +++ b/Apple2/DriveFirmware.asm @@ -36,16 +36,27 @@ MenuCommand = $08 .org SLOT*$100 + $C000 ;ID bytes for booting and drive detection - cpx #$20 ;ID bytes for ProDOS and the - cpx #$00 ; Apple Autostart ROM + cpx #$20 ;ID bytes for ProDOS + cpx #$00 ; cpx #$03 ; + cpx #$3C ;ID byte for Autostart ROM - ldx #SLOT*$10 - stx $2b - stx Unit - -;force EPROM to second page on boot lda #$3f ;set all flags high and page 3 of EPROM for menu + jmp PageJump + +;The following bytes must exist in this location for Pascal communications +;as they are standard pointers for entry points +.byte CommInit&$00FF ;low byte of rts for init of Pascal comms +.byte CommRead&$00FF ; low byte of read for Pascal comms +.byte CommWrite&$00FF ; low byte of write for Pascal comms +.byte CommStatus&$00FF ; low byte of rts for status of Pascal comms + +CommInit: + lda #$0f ; set all flags high and page 0 for comm driver + sta OutputFlags + ldx #$00 ; set error code to 0 for success + rts + PageJump: sta OutputFlags jmp Start ;this jump is only called if coming in from PageJump with A=$0f @@ -58,6 +69,10 @@ DriverEntry: ;load first two blocks and execute to boot Start: + ldx #SLOT*$10 + stx $2b + stx Unit + lda #$01 ;set read command sta Command @@ -71,6 +86,21 @@ Start: jmp $801 ;execute the block +CommRead: + jsr GetByte + ldx #$00 ; clear error code + rts + +CommWrite: + jsr SendByte + ldx #$00 ; clear error code + rts + +CommStatus: + ldx #$00 ; clear error code + sec ; set carry to indicate ready to read or write + rts + ; ProDOS Driver code ; First check that this is the right drive Driver: @@ -78,7 +108,7 @@ Driver: lda Command; Check which command is being requested beq GetStatus ;0 = Status command cmp #ReadBlockCommand - beq ReadBlockAndSetTime + beq ReadBlock cmp #WriteBlockCommand beq WriteBlock sec ;set carry as we don't support any other commands @@ -94,22 +124,7 @@ GetStatus: rts ; ProDOS Read Block Command -ReadBlockAndSetTime: - lda BlockHi ; only get the time if block 0002 - bne readBlock - lda BlockLo - cmp #$02 - bne readBlock - ldy #$00 ;Get the current time on each block read for now - lda #GetTimeCommand - jsr SendByte -getTimeByte: - jsr GetByte - sta $bf90,y - iny - cpy #$04 - bne getTimeByte -readBlock: +ReadBlock: lda #ReadBlockCommand ;read the block after setting the clock jsr SendByte lda BlockLo diff --git a/Apple2/FileAccessFirmware.asm b/Apple2/FileAccessFirmware.asm index 871c748..9c5d194 100644 --- a/Apple2/FileAccessFirmware.asm +++ b/Apple2/FileAccessFirmware.asm @@ -2,9 +2,9 @@ ; Use of this source code is governed by an MIT ; license that can be found in the LICENSE file. -; This file contains the source for the firmware -; that was formerly used to copy files from RPi -; to Apple II RAM +; This file formerly contained the source for the +; firmware that had a file access +; but is now empty except required common bytes ;ProDOS Zero Page Command = $42 ;ProDOS Command @@ -33,117 +33,41 @@ LoadFileCommand = $06 SaveFileCommand = $07 MenuCommand = $08 -InputString = $fd67 -Monitor = $ff59 - .org SLOT*$100 + $C000 ;ID bytes for booting and drive detection - cpx #$20 ;ID bytes for ProDOS and the - cpx #$00 ; Apple Autostart ROM + cpx #$20 ;ID bytes for ProDOS + cpx #$00 ; cpx #$03 ; + cpx #$3C ;ID byte for Autostart ROM - ldx #SLOT*$10 - stx $2b - stx Unit - -;force EPROM to second page on boot lda #$3f ;set all flags high and page 3 of EPROM for menu + jmp PageJump + +;The following bytes must exist in this location for Pascal communications +;as they are standard pointers for entry points +.byte CommInit&$00FF ;low byte of rts for init of Pascal comms +.byte $43 ; low byte of read for Pascal comms +.byte $49 ; low byte of write for Pascal comms +.byte $4F ; low byte of rts for status of Pascal comms + +CommInit: + lda #$0f ; set all flags high and page 0 for comm driver + sta OutputFlags + ldx #$00 ; set error code to 0 for success + rts + PageJump: sta OutputFlags - jmp Start ;this jump is only called if coming in from PageJump with A=$2f + jmp Start ;this jump is only called if coming in from PageJump with A=$0f ;entry points for ProDOS DriverEntry: lda #$0f ;set all flags high and page 0 of EPROM sta OutputFlags + jmp Start ; this is never called as the EPROM page changes +;load first two blocks and execute to boot Start: - lda #$a4 - sta $33 - -GetFilename: - jsr InputString - -LoadFile: - lda #$00 - sta BufferLo - lda #$20 - sta BufferHi - lda #$06 ; send command 6 = load - jsr SendByte - ldy #$00 -sendFilename: - lda $0200,y - cmp #$8d - beq sendNullTerminator - and #$7f - jsr SendByte - iny - bne sendFilename -sendNullTerminator: - lda #$00 - jsr SendByte - - jsr GetByte - sta BlockLo ; not really a block, just using the memory space - jsr GetByte - sta BlockHi -NextPage: - lda BlockHi - beq ReadFinalPage - ldy #$00 -NextByte: - jsr GetByte - sta (BufferLo),y - iny - bne NextByte - inc BufferHi - dec BlockHi - bne NextPage -ReadFinalPage: - lda BlockLo - beq ExitToMonitor - ldy #$00 -NextByteFinal: - jsr GetByte - sta (BufferLo),y - iny - cpy BlockLo - bne NextByteFinal -ExitToMonitor: - jsr Monitor - -SendByte: - bit InputFlags - bvs SendByte - sta OutputByte -.if HW_TYPE = 0 - lda #$2e ; set bit 0 low to indicate write started - sta OutputFlags -finishWrite: - bit InputFlags - bvc finishWrite - lda #$2f - sta OutputFlags -.endif - rts - -GetByte: -.if HW_TYPE = 0 - ldx #$2d ;set read flag low - stx OutputFlags -.endif -waitRead: - bit InputFlags - bmi waitRead - lda InputByte -.if HW_TYPE = 0 - ldx #$2f ;set all flags high - stx OutputFlags -finishRead: - bit InputFlags - bpl finishRead -.endif end: rts @@ -152,6 +76,6 @@ end: .endrepeat .byte 0,0 ;0000 blocks = check status -.byte 7 ;bit set(0=status 1=read 2=write) unset(3=format, 4/5=number of volumes, 6=interruptable, 7=removable) +.byte 23 ;bit set(0=status 1=read 2=write) unset(3=format, 4/5=number of volumes, 6=interruptable, 7=removable) .byte DriverEntry&$00FF ;low byte of entry diff --git a/Apple2/MenuFirmware.asm b/Apple2/MenuFirmware.asm index bc229ea..e03ccb5 100644 --- a/Apple2/MenuFirmware.asm +++ b/Apple2/MenuFirmware.asm @@ -45,21 +45,32 @@ vtab = $25 BasL = $28 htab80 = $057b - .org SLOT*$100 + $C000 +.org SLOT*$100 + $C000 ;ID bytes for booting and drive detection - cpx #$20 ;ID bytes for ProDOS and the - cpx #$00 ; Apple Autostart ROM + cpx #$20 ;ID bytes for ProDOS + cpx #$00 ; cpx #$03 ; + cpx #$3C ;ID byte for Autostart ROM - ldx #SLOT*$10 - stx $2b - stx Unit + lda #$3f ;set all flags high and page 3 of EPROM for menu + jmp PageJump + +;The following bytes must exist in this location for Pascal communications +;as they are standard pointers for entry points +.byte CommInit&$00FF ;low byte of rts for init of Pascal comms +.byte $43 ; low byte of read for Pascal comms +.byte $49 ; low byte of write for Pascal comms +.byte $4F ; low byte of rts for status of Pascal comms + +CommInit: + lda #$0f ; set all flags high and page 0 for comm driver + sta OutputFlags + ldx #$00 ; set error code to 0 for success + rts -;force EPROM to second page on boot - lda #$3f ;set all flags high and page 1 of EPROMi PageJump: sta OutputFlags - jmp Start + jmp Start ;this jump is only called if coming in from PageJump with A=$0f ;entry points for ProDOS DriverEntry: @@ -191,9 +202,9 @@ Text: .byte "(c)2020-2024 Terence J. Boldt",$8d .byte $8d .if HW_TYPE = 0 -.byte "Waiting for RPi FW:0010..." +.byte "Waiting for RPi FW:0011" .else -.byte "Waiting for RPi FW:8010..." +.byte "Waiting for RPi FW:8011" .endif end: .byte $00 @@ -205,4 +216,3 @@ end: .byte 0,0 ;0000 blocks = check status .byte 7 ;bit set(0=status 1=read 2=write) unset(3=format, 4/5=number of volumes, 6=interruptable, 7=removable) .byte DriverEntry&$00FF ;low byte of entry - diff --git a/Apple2/RPi.Command.asm b/Apple2/RPi.Command.asm index e12b1d8..ae04a3a 100644 --- a/Apple2/RPi.Command.asm +++ b/Apple2/RPi.Command.asm @@ -33,6 +33,7 @@ MenuCommand = $08 InputString = $fd67 PrintChar = $fded +PrintHex = $fde3 Keyboard = $c000 ClearKeyboard = $c010 Wait = $fca8 @@ -50,53 +51,68 @@ ESC = $9b .endmacro .org $2000 - ldx #$07 ; start at slot 7 -DetectSlot: +; Find Apple2-IO-RPi card + ldx #$06 + ldy #$09 +CheckIdBytes: + lda $C700,y ; !! Self modifying code + cmp IdBytes,y + bne NextCard + dey + bne CheckIdBytes + jmp FoundCard +NextCard: + dec CheckIdBytes+2 + ldy #$09 + dex + bne CheckIdBytes +CardNotFound: ldy #$00 - lda #$fc - sta SlotL +PrintCardNotFound: + lda TextCardNotFound,y + beq Failed + jsr PrintChar + iny + bne PrintCardNotFound +Failed: + rts +FoundCard: + ldy #$00 +PrintCardFound: + lda TextCardFound,y + beq PrintCardNumber + jsr PrintChar + iny + bne PrintCardFound +PrintCardNumber: + inx txa - ora #$c0 - sta SlotH - lda (SlotL),y - bne nextSlot - iny - lda (SlotL),y - bne nextSlot - iny - lda (SlotL),y - cmp #$17 - bne nextSlot - iny - lda (SlotL),y - cmp #$14 - bne nextSlot + jsr PrintHex + lda #$8D + jsr PrintChar + +SetOffsetForCard: txa asl asl asl asl tax - clc - bcc Start -nextSlot: - dex - bne DetectSlot - rts + + Start: stx slotx + $1e01 ;set the slot for the driver - ldy #$00 + ldy #$00 PrintString: lda Text,y beq copyDriver - ora #$80 jsr PrintChar iny bne PrintString copyDriver: ldy #$00 copyDriverByte: - lda $2100,y + lda $2200,y sta $0300,y iny cpy #$e6 @@ -140,10 +156,26 @@ a2help: .byte "a2help", $00 Text: - aschi "RPI command version: 000E" - .byte $8d +.if HW_TYPE = 0 + aschi "RPI command version: 000F (classic)" +.else + aschi "RPI command version: 800F (pico)" +.endif +.byte $8d +.byte $00 + +IdBytes: +.byte $E0,$20,$E0,$00,$E0,$03,$E0,$3C,$A9,$3F + +TextCardFound: + aschi "Found Apple2-IO-RPi in slot " +.byte $00 + +TextCardNotFound: + aschi "Apple2-IO-RPi not found" +.byte $8D end: - .byte $00 +.byte $00 .repeat 255-