Skip to content

Commit

Permalink
IRQ race condition fix
Browse files Browse the repository at this point in the history
  • Loading branch information
MichalPleban committed Jan 17, 2021
1 parent c91fb21 commit 58eff90
Show file tree
Hide file tree
Showing 8 changed files with 88 additions and 68 deletions.
Binary file modified dist/prg/6509.prg
Binary file not shown.
Binary file modified dist/rom/8088.bin
Binary file not shown.
Binary file modified dist/rom/8088_devel.bin
Binary file not shown.
Binary file modified dist/rom/payload.bin
Binary file not shown.
Binary file modified dist/upgrade/upgrade.com
Binary file not shown.
131 changes: 79 additions & 52 deletions src/6509/ipc.asm
Expand Up @@ -121,6 +121,10 @@ disk_status:
printer_flag:
.byt 0

; Flag for interrupt nesting.
nesting_flag:
.byt 1
.res ($0830-*), $FF
;--------------------------------------------------------------------
Expand All @@ -140,7 +144,7 @@ printer_flag:
.word ipc_19_serial_in
.word ipc_1a_serial_out
.word ipc_1b_serial_config
.word ipc_1c_exit
.word 0
.word ipc_1d_sid_control
.word 0
.word 0
Expand Down Expand Up @@ -170,18 +174,7 @@ cmd_n:
;--------------------------------------------------------------------
my_irq:
lda ACIA_Command
and #$F7
sta ACIA_Command
lda #>irq_handler
pha
lda #<irq_handler
pha
php
pha
pha
pha
jmp (old_irq)
jmp new_irq
;--------------------------------------------------------------------
; Actual interrupt handler function.
Expand Down Expand Up @@ -225,16 +218,7 @@ clear_buffer:
irq_end:
lda #$00
sta KeybufIndex
lda ACIA_Command
ora #$08
sta ACIA_Command
pla
tay
pla
tax
pla
cli
rti
rts
;--------------------------------------------------------------------
; IPC function 10 - check scancode in keyboard buffer.
Expand Down Expand Up @@ -262,29 +246,6 @@ ipc_20_kbd_clear:
sta KeybufIndex
rts

;--------------------------------------------------------------------
; Information about IPC function parameters. For every function:
; * low nibble = number of input parameters.
; * hight nibble = number of output parameters.
; The location of this table is hardcoded to $0910 in the KERNAL.
;--------------------------------------------------------------------

.res ($0910-*), $FF
.byt $00,$01,$02,$03,$04,$05,$06,$07
.byt $08,$09,$0a,$0b,$0c,$0d,$0e,$0f
.byt $40,$40,$23,$23,$66,$40,$4b,$4b
.byt $40,$30,$23,$25,$00,$25,$00,$00
.byt $00,$4b,$0a
;--------------------------------------------------------------------
; 8088 INT memory vectors
;--------------------------------------------------------------------

vectors:
.word $FFF5, $F000
.word $F1E2, $F000

;--------------------------------------------------------------------
; IPC function 11 - read from keyboard.
;--------------------------------------------------------------------
Expand All @@ -300,6 +261,22 @@ ipc_11_loop:
jsr CLRCH
clc
jmp ipc_end

;--------------------------------------------------------------------
; Information about IPC function parameters. For every function:
; * low nibble = number of input parameters.
; * hight nibble = number of output parameters.
; The location of this table is hardcoded to $0910 in the KERNAL.
;--------------------------------------------------------------------

.res ($0910-*), $FF
.byt $00,$01,$02,$03,$04,$05,$06,$07
.byt $08,$09,$0a,$0b,$0c,$0d,$0e,$0f
.byt $40,$40,$23,$23,$66,$40,$4b,$4b
.byt $40,$30,$23,$25,$00,$25,$00,$00
.byt $00,$4b,$0a
;--------------------------------------------------------------------
; IPC function 12 - write to screen.
Expand Down Expand Up @@ -594,7 +571,6 @@ calc_drive:

; Calculate address from 8088 segment and offset.
calc_addr:
cli
sta TPI1_ActIntReg
lda ipc_buffer+10
sta load_addr
Expand Down Expand Up @@ -1016,7 +992,6 @@ getin_loop:
dec buffer_size
pla
ldx #$03
cli
getin_end:
clc
rts
Expand Down Expand Up @@ -1051,9 +1026,6 @@ ipc_14_screen_driver:
jsr $0403
rts

ipc_1c_exit:
jmp ($FFFC)
;--------------------------------------------------------------------
; IPC function 15 - read CIA counter A
;--------------------------------------------------------------------
Expand Down Expand Up @@ -1084,7 +1056,62 @@ ipc_1d_sid_control:
lda ipc_buffer+4
and #$01
ora #$20
sta $0FFF
sta $DA0B
clc
jmp ipc_end

;--------------------------------------------------------------------
; New IRQ Handler
;--------------------------------------------------------------------

new_irq:
lda $01
pha
cld
; Check TPI interrupt source
lda $DE07
bne new_irq_1
sta $DE07
jmp $FCA2
new_irq_1:
; IRQ from the 8088? If yes, redirect to our handler.
cmp #$08
beq new_irq_2
; IRQ from 50Hz timer? If yes, redirect to our handler.
cmp #$01
beq new_irq_5
; Redirect to normal IRQ handler.
jmp $FBF5
new_irq_2:
; Clear IRQ flag at the CIA
lda $DB0D
; Decrease nesting level
dec nesting_flag
; Nested interrupt? If yes then exit.
bit nesting_flag
bmi new_irq_4
new_irq_3:
lda ACIA_Command
and #$F7
sta ACIA_Command
cli
lda #$00
sta $DB02
lda $DB00
jsr $FD48
inc nesting_flag
; Nested interrupt arrived in the meantime? If yes then repeat.
lda nesting_flag
cmp #1
bne new_irq_3
new_irq_4:
lda ACIA_Command
ora #$08
sta ACIA_Command
jsr irq_handler
jmp $FC9F
new_irq_5:
jsr $E013
jsr $F979
jsr irq_handler
jmp $FC9F
4 changes: 2 additions & 2 deletions src/8088/build.inc
Expand Up @@ -3,8 +3,8 @@
%define SOFTWARE_VERSION "A"

; Software build (starting with 1)
%define SOFTWARE_BUILD 293
%define SOFTWARE_BUILDS "293"
%define SOFTWARE_BUILD 363
%define SOFTWARE_BUILDS "363"

db SOFTWARE_VERSION
dw SOFTWARE_BUILD
21 changes: 7 additions & 14 deletions src/8088/payload/ipc.asm
Expand Up @@ -47,6 +47,12 @@ IPCData equ 000Ah ; Offset of the data trasfer area (16 bytes)
IPC:
call 0F000h:0F003h
ret
push cx
mov cx, 20
IPC_No_Handshake2:
loop IPC_No_Handshake2
pop cx
ret

IPC_GetSeg:
xor cx, cx
Expand Down Expand Up @@ -255,9 +261,7 @@ Clock_Init:
ret
; --------------------------------------------------------------------------------------
; Output character to the printer.
; Input:
; AL - character code
; Initialize the IPC library.
; --------------------------------------------------------------------------------------

IPC_Reset:
Expand Down Expand Up @@ -488,17 +492,6 @@ IPC_SerialOut:
IPC_Leave
ret

; --------------------------------------------------------------------------------------
; Reset the computer.
; --------------------------------------------------------------------------------------

IPC_ResetComputer:
IPC_Enter
mov [IPCData+2], al
IPC_Call 12h
IPC_Leave
ret

; --------------------------------------------------------------------------------------
; Play a tone using the SID chip.
; Input:
Expand Down

0 comments on commit 58eff90

Please sign in to comment.