Skip to content

Commit 15375da

Browse files
FozzTexxtschak909
authored andcommitted
DOS 2.10 doesn't have enough stack space so swap in our own before dispatching commands
1 parent 01ff8b6 commit 15375da

File tree

3 files changed

+50
-9
lines changed

3 files changed

+50
-9
lines changed

fujicom/fujicom.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
#define TIMEOUT_SLOW 15 * 1000
2121
#define MAX_RETRIES 5
2222
#ifndef SERIAL_BPS
23-
#define SERIAL_BPS 9600
23+
#define SERIAL_BPS 115200
2424
#endif /* SERIAL_BPS */
2525

2626
PORT fn_port;

sys/dispatch.c

Lines changed: 47 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,15 @@
88

99
#undef DEBUG
1010

11+
#define STACK_SWAP
12+
#ifdef STACK_SWAP
13+
#define STACK_SIZE 1024
14+
char our_stack[STACK_SIZE]; /* our internal stack */
15+
uint16_t dos_ss; /* DOS's saved SS at entry */
16+
uint16_t dos_sp; /* DOS's saved SP at entry */
17+
uint16_t our_ss, our_sp;
18+
#endif /* STACK_SWAP */
19+
1120
#define disable() _asm { cli }
1221
#define enable() _asm { sti }
1322

@@ -56,23 +65,55 @@ void far Interrupt(void)
5665
{
5766
push_regs();
5867

68+
#ifdef STACK_SWAP
69+
// Save ss:sp and switch to our internal stack.
70+
71+
our_sp = (FP_OFF(our_stack) + 15) >> 4;
72+
our_ss = FP_SEG(our_stack) + our_sp;
73+
our_sp = STACK_SIZE - 2 - (((our_sp - (FP_OFF(our_stack) >> 4)) << 4)
74+
- (FP_OFF(our_stack) & 0xf));
75+
76+
_asm {
77+
mov dos_ss, ss;
78+
mov dos_sp, sp;
79+
80+
mov ax, our_ss;
81+
mov cx, our_sp;
82+
83+
// activate new stack
84+
//cli;
85+
mov ss, ax;
86+
mov sp, cx;
87+
//sti;
88+
}
89+
#endif /* STACK_SWAP */
90+
5991
if (fpRequest->command > MAXCOMMAND
6092
|| !(currentFunction = dispatchTable[fpRequest->command])) {
61-
fpRequest->status = DONE_BIT | ERROR_BIT | UNKNOWN_CMD;
93+
fpRequest->status = ERROR_BIT | UNKNOWN_CMD;
6294
}
6395
else {
6496
#ifdef DEBUG
65-
printDTerm("Command 0x$");
66-
printHex(fpRequest->command, 2, '0');
97+
consolef("Command 0x%02x", fpRequest->command);
6798
#endif
6899
fpRequest->status = currentFunction(fpRequest);
69100
#ifdef DEBUG
70-
printDTerm(" result: 0x$");
71-
printHex(fpRequest->status, 4, '0');
72-
printDTerm("\r\n$");
101+
consolef(" result: 0x%04x\n", fpRequest->status);
73102
#endif
74103
}
75104

105+
fpRequest->status |= DONE_BIT;
106+
107+
#ifdef STACK_SWAP
108+
// Switch the stack back
109+
_asm {
110+
//cli;
111+
mov ss, dos_ss;
112+
mov sp, dos_sp;
113+
//sti;
114+
}
115+
#endif /* STACK_SWAP */
116+
76117
pop_regs();
77118
return;
78119
}

sys/init.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ uint16_t Init_cmd(SYSREQ far *req)
9393

9494
req->init.num_units = FN_MAX_DEV;
9595

96-
for (idx = 0; idx < FN_MAX_DEV; idx++) {
96+
for (idx = 0; idx < req->init.num_units; idx++) {
9797
/* 5.25" 360k BPB */
9898
fn_bpb_table[idx].bps = 512;
9999
fn_bpb_table[idx].spau = 2;
@@ -160,7 +160,7 @@ uint8_t get_set_time(uint8_t set_flag)
160160

161161
intdos(&regs, &regs);
162162

163-
consolef("MS-DOS Time now set from FujiNet\n$");
163+
consolef("MS-DOS Time now set from FujiNet\n");
164164
}
165165

166166
return 0;

0 commit comments

Comments
 (0)