Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into linux
Browse files Browse the repository at this point in the history
  • Loading branch information
markjfisher committed Feb 2, 2024
2 parents 77ee59a + 7927569 commit edc0801
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 13 deletions.
32 changes: 20 additions & 12 deletions firmware/SPoverSLIP/spoverslip.s
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ header:
cpx #$03
cpx #$00

; this is a copy of Oliver Schmidt code for Reload Emulator at
; This is a copy of Oliver Schmidt code for Reload Emulator at
; https://github.com/vsladkov/reload-emulator/pull/1/files#diff-b889f9e1f8b8d8898b043495b2e25bfc19a9b12655456af92ebab9f92c9e20b0
; It attempts to load block 0000 into $0800, and run the routine at $0801.
; If prodos tells us there is no disk, it detects if we are in an autoboot scan and continues that,
; otherwise, it reports an error, as someone else is trying to run the code at our slot address Cn00 (e.g PR#n)

stx blockl
stx blockh
Expand All @@ -51,25 +54,27 @@ n16_1:
cn3:
jsr driver ; need to adjust the location as it compiles to c0, but need cN
bcs do_err
ldx $0800 ; disk II sector count
ldx $0800 ; disk II block count
dex
bne do_err ; must be 1 sector
ldx $0801 ; first opcode from read sector
beq do_err ; must not be BRK
bne do_err ; must be 1
ldx $0801 ; first opcode from block read
beq do_err ; must not be BRK (prodos seems to be $38 for SEC)
n16_2:
ldx #$00 ; replaced by Card with slot * 16 == Drive 1 indicator
jmp $0801 ; run, implicit RTS at the end will return to caller
ldx #$00 ; (slot * 16) == Drive 1 indicator for this slot (drive 2 would have high bit set)
jmp $0801 ; run from 1st byte of loaded block

; Check if this is an autoboot scan (Cn00 will be in locations 00, 01), and MSLOT is also the current card being read, i.e. Cn.
; If it is, continue the autoscan, otherwise someone jumped to Cn00 (us) but we did not have a disk to use.
do_err:
ldx loc0
bne errexit
ldx loc1
cpx mslot
bne errexit
bne errexit ; 0000 does not contain a Cn00 address, so we are not autoboot scanning
cn1:
cpx #$00 ; written to by emulator with Cn value for slot
cpx #$00 ; written to by emulator with Cn value for slot, check if mslot (current scan) is our slot
bne errexit
jmp sloop
jmp sloop ; we did see our card in 0000, but we are not bootable, and mslot etc hinted we are scanning, so continue scanning

errexit:
jsr setscr
Expand Down Expand Up @@ -98,11 +103,10 @@ do_prodos:
lda #pdmagic

; used to locate where the firmware needs to write slot value.
; DO NOT PUT ANYTHING BETWEEN LABEL AND "sta $c000"
n2:
sta $c000 ; 00 is overwritten by emulator when loading firmware to correct n2 value for this slot

; emulator does everything: getting data from device, writing to memory, fixing return address on stack, setting A/X/Y
; emulator does everything: getting data from device, writing to memory, fixing return address on stack (if SmartPort call), setting A/X/Y

cmp #$01 ; set carry if a is not 0
rts
Expand All @@ -112,12 +116,16 @@ errtext:

; write data to the end of the block
.res $0100-10-<*

; all these bytes are read by AppleWin card code to determine where to write into firmware the current slot values needed by firmware
.byte <(n16_1+1) ; slot * 16 for direct boot #1
.byte <(n16_2+1) ; slot * 16 for direct boot #2
.byte <(cn1+1) ; high byte of 0xCn00, needed in error routine #1 (SINGLE BYTE)
.byte <(cn2+2) ; high byte of 0xCn00, needed in error routine #2 (HIGH BYTE of pair)
.byte <(cn3+2) ; high byte of 0xCn00, needed in jsr driver (HIGH BYTE of pair)
.byte <(n2+1) ; low byte of 0xC0n2 address for initiating the SP command

; final bytes for Cn00 for A2 to understand about this card
.byte $00, $00 ; total blocks, causes status to be called to get value
.byte $f7 ; status bits (http://www.easy68k.com/paulrsm/6502/PDOS8TRM.HTM)
.byte <driver ; driver entry point
38 changes: 37 additions & 1 deletion source/SmartPortOverSlip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ void SmartPortOverSlip::handle_smartport_call()
mem[regs.sp + 1] = rts_location & 0xff;
mem[regs.sp + 2] = (rts_location >> 8) & 0xff;

int dirty_page_start = ((regs.sp + 1) & 0xFF00) >> 8;
int dirty_page_end = ((regs.sp + 2) & 0xFF00) >> 8;
memdirty[dirty_page_start] = 0xFF;
memdirty[dirty_page_end] = 0xFF;


// Deal with unit 0, status 0 call to return device count, doesn't need connection details.
if (unit_number == 0 && mem[params_loc] == 0)
{
Expand Down Expand Up @@ -203,7 +209,7 @@ void SmartPortOverSlip::handle_prodos_call()
const uint8_t slot_num = (mem[0x43] & 0x70) >> 4;
const uint8_t command = mem[0x42];

LogFileOutput("SmartPortOverSlip prodos, drive_num: %d, slot_num: %d, command: %d\n", drive_num, slot_num, command);
// LogFileOutput("SmartPortOverSlip prodos, drive_num: %d, slot_num: %d, command: %d\n", drive_num, slot_num, command);

if (slot_num != m_slot)
{
Expand Down Expand Up @@ -326,6 +332,9 @@ void SmartPortOverSlip::handle_prodos_read(uint8_t drive_num, std::pair<int, int
std::move(response),
[this, buffer_location](const ReadBlockResponse *rbr) {
memcpy(mem + buffer_location, rbr->get_block_data().data(), 512);
int dirty_page_start = (buffer_location & 0xFF00) >> 8;
memdirty[dirty_page_start] = 0xFF;
memdirty[dirty_page_start + 1] = 0xFF;
regs.a = 0;
regs.x = 0;
regs.y = 2; // 512 bytes
Expand All @@ -345,6 +354,9 @@ void SmartPortOverSlip::handle_prodos_write(uint8_t drive_num, std::pair<int, in
request.set_block_number_from_bytes(mem[0x46], mem[0x47], 0);
// put data into the request we're sending
request.set_block_data_from_ptr(mem, buffer_location);
//int dirty_page_start = (buffer_location & 0xFF00) >> 8;
//memdirty[dirty_page_start] = 0xFF;
//memdirty[dirty_page_start + 1] = 0xFF;
auto response = Requestor::send_request(request, id_connection.second.get());

handle_response<WriteBlockResponse>(
Expand Down Expand Up @@ -384,6 +396,11 @@ void SmartPortOverSlip::device_count(const WORD sp_payload_loc)
mem[sp_payload_loc + 3] = 0x46;
mem[sp_payload_loc + 4] = 0x0A; // version 1.00 Alpha = $100A
mem[sp_payload_loc + 5] = 0x10;
int dirty_page_start = (sp_payload_loc & 0xFF00) >> 8;
int dirty_page_end = ((sp_payload_loc + 5) & 0xFF00) >> 8;
memdirty[dirty_page_start] = 0xFF;
memdirty[dirty_page_end] = 0xFF;

regs.a = 0;
regs.x = 6;
regs.y = 0;
Expand All @@ -399,6 +416,11 @@ void SmartPortOverSlip::read_block(const BYTE unit_number, Connection *connectio

handle_response<ReadBlockResponse>(std::move(response), [this, buffer_location](const ReadBlockResponse *rbr) {
memcpy(mem + buffer_location, rbr->get_block_data().data(), 512);

int dirty_page_start = (buffer_location & 0xFF00) >> 8;
memdirty[dirty_page_start] = 0xFF;
memdirty[dirty_page_start + 1] = 0xFF;

regs.a = 0;
regs.x = 0;
regs.y = 2; // 512 bytes
Expand Down Expand Up @@ -426,6 +448,13 @@ void SmartPortOverSlip::read(const BYTE unit_number, Connection *connection, con
handle_response<ReadResponse>(std::move(response), [sp_payload_loc](const ReadResponse *rr) {
const auto response_size = rr->get_data().size();
memcpy(mem + sp_payload_loc, rr->get_data().data(), response_size);

int dirty_page_start = (sp_payload_loc & 0xFF00) >> 8;
int dirty_page_end = ((sp_payload_loc + response_size) & 0xFF00) >> 8;
for (int i = dirty_page_start; i <= dirty_page_end; i++) {
memdirty[i] = 0xFF;
}

regs.a = 0;
regs.x = response_size & 0xff;
regs.y = (response_size >> 8) & 0xff;
Expand All @@ -451,6 +480,13 @@ void SmartPortOverSlip::status_sp(const BYTE unit_number, Connection *connection
handle_response<StatusResponse>(std::move(response), [sp_payload_loc](const StatusResponse *sr) {
const auto response_size = sr->get_data().size();
memcpy(mem + sp_payload_loc, sr->get_data().data(), response_size);

int dirty_page_start = (sp_payload_loc & 0xFF00) >> 8;
int dirty_page_end = ((sp_payload_loc + response_size) & 0xFF00) >> 8;
for (int i = dirty_page_start; i <= dirty_page_end; i++) {
memdirty[i] = 0xFF;
}

regs.a = 0;
regs.x = response_size & 0xff;
regs.y = (response_size >> 8) & 0xff;
Expand Down

0 comments on commit edc0801

Please sign in to comment.