; this file has the interrupt handlers
; ------------------------------------

; WARNGING: THIS FILE IS BIG AND UGLY!

;---------------------------------------------------------
; setup the interrupt handlers
;---------------------------------------------------------

; note: the first 1k of memory (0000:0000 - 0000:3ffh) is reservered
; for interrupt handlers

setinthandlers:
	push es			; save the old values
	push ax
	push bx

	xor bx,bx		; clear/empty ax
	mov es,bx		; set the extra segment to 0

	; load the segment address of intX into the extra segment
	; load the offset of intX into ax (in other words load the
	; pointer into es:bx

	;--------------------------------------------------------

	; syscall (0x45/0x69) interrupt handler
	; (at addr 0x45 * 4 = 0000:0114) [4 byte alignment]

	mov ax,0x45

	mov bl,4		; get offset in interrupt handler (int * 4)
	mul bl
		
	mov bx,ax		; put offset into bx

	mov ax,softint45
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax
	
	; -------------------------------

	; syscall (0x45/0x69) interrupt handler
	; (at addr 0x45 * 4 = 0000:0114) [4 byte alignment]

	mov ax,0x69

	mov bl,4		; get offset in interrupt handler (int * 4)
	mul bl
		
	mov bx,ax		; put offset into bx

	mov ax,softint69
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; syscall (45/69) interrupt handler
	mov ax,45

	mov bl,4		; get offset in interrupt handler (int * 4)
	mul bl
		
	mov bx,ax		; put offset into bx

	mov ax,softint45
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; syscall (45/69) interrupt handler
	mov ax,69

	mov bl,4		; get offset in interrupt handler (int * 4)
	mul bl
		
	mov bx,ax		; put offset into bx

	mov ax,softint69
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax


	;--------------------------------------------------------


	; exp 0 handler (at 0000:0000)
	xor bx,bx		; clear/empty bx (offset)

	mov ax,exp0
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 1 handler (at 0000:0004)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp1
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 2 handler (at 0000:0008)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp2
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 3 handler (at 0000:000C)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp3
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 4 handler (at 0000:0010)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp4
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 5 handler (at 0000:0014)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp5
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 6 handler (at 0000:0018)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp6
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 7 handler (at 0000:001C)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp7
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 8 handler (at 0000:0020)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp8
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 9 handler (at 0000:0024)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp9
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax
	; -------------------------------

	; exp 10 handler (at 0000:0028)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp10
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------
	; exp 11 handler (at 0000:002C)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp11
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 12 handler (at 0000:0030)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp12
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 13 handler (at 0000:0034)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp13
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 14 handler (at 0000:0038)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp14
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 15 handler (at 0000:003C)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp15
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 16 handler (at 0000:0040)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp16
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 17 handler (at 0000:0044)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp17
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax

	; -------------------------------

	; exp 18 handler (at 0000:0048)
	add bx,4		; increment bx by 4 (on 4 byte bounds)

	mov ax,exp18
	mov [es:bx],ax

	mov ax,ds
	mov [es:bx+2],ax


	;--------------------------------------------------------


	pop bx			; restore the old values	
	pop ax
	pop es

	ret


;----------------------------------------------------
; start of CPU exception handlers (0-15)
;----------------------------------------------------

exp0:
	; savestack 
	; push other things

	iret			; return from interrupt

exp1:
	; savestack 
	; push other things

	iret			; return from interrupt

exp2:
	; savestack 
	; push other things

	iret			; return from interrupt

exp3:
	; savestack 
	; push other things

	iret			; return from interrupt

exp4:
	; savestack 
	; push other things

	iret			; return from interrupt

exp5:
	; savestack 
	; push other things

	iret			; return from interrupt

exp6:
	; savestack 
	; push other things

	iret			; return from interrupt

exp7:
	; savestack 
	; push other things

	iret			; return from interrupt

exp8:
	; savestack 
	; push other things

	iret			; return from interrupt

exp9:
	; savestack 
	; push other things

	iret			; return from interrupt

exp10:
	; savestack 
	; push other things

	iret			; return from interrupt

exp11:
	; savestack 
	; push other things

	iret			; return from interrupt

exp12:
	; savestack 
	; push other things

	iret			; return from interrupt

exp13:
	; savestack 
	; push other things

	iret			; return from interrupt

exp14:
	; savestack 
	; push other things

	iret			; return from interrupt

exp15:
	; savestack 
	; push other things

	iret			; return from interrupt


exp16:
	; savestack 
	; push other things

	iret			; return from interrupt

exp17:
	; savestack 
	; push other things

	iret			; return from interrupt

exp18:
	; savestack 
	; push other things

	iret			; return from interrupt


;----------------------------------------------------
; start of software interrupt handlers
; (45, 69, 0x45, 0x69) = all map to same syscall int
;----------------------------------------------------

; syscall interrupt[s]
softint45:
softint69:
	; savestack 
	; push other things

	iret			; return from interrupt