I am sorry but I didn't read the whole thread but this is my keyborad/mouse/joystick handling routine:
Code: Select all
;
; keyboard interrupt handler
; (c) 1997 Mr Ni! the Great
;
; Geeft de volgende informatie:
; mouse_x: dc.w 0 ; volatile int mouse_x;
; mouse_y: dc.w 0 ; volatile int mouse_y;
; click_x: dc.w 0 ; volatile int click_x;
; click_y: dc.w 0 ; volatile int click_y;
; buttons: dc.b 0 ; volatile char buttons;
; click_f: dc.b 0 ; volatile char click_f; /* flag shows buttons that caused the click */
; joy0: dc.b 0 ; volatile byte joy0;
; joy1: dc.b 0 ; volatile byte joy1;
; joy2: dc.b 0 ; volatile byte joy2; /* cursor joystick */
; last_key: dc.b 0 ; volatile byte last_key;
;
EXPORT key_info
EXPORT key_interrupt
EXPORT initmuis ; void initmuis(void)
EXPORT showmuis ; void showmuis(int x, int y, void* screen)
EXPORT hidemuis ; void hidemuis(void)
TEXT
JOY_UP equ 1
JOY_LEFT equ 4
JOY_RIGHT equ 8
JOY_DOWN equ 2
JOY_FIRE equ $80
;MOUSE_X_MIN equ 0 implicit zero check
MOUSE_X_MAX equ 319
;MOUSE_Y_MIN equ 0 implicit zero check
MOUSE_Y_MAX equ 199
;/* key handeler info */
;struct key_handler_info_struct
key_info:
mouse_x: dc.w MOUSE_X_MAX/2 ; volatile int mouse_x;
mouse_y: dc.w MOUSE_Y_MAX/2 ; volatile int mouse_y;
click_x: dc.w 0 ; volatile int click_x;
click_y: dc.w 0 ; volatile int click_y;
buttons: dc.b 0 ; volatile char buttons;
click_f: dc.b 0 ; volatile char click_f; /* flag shows buttons that caused the click */
joy0: dc.b 0 ; volatile byte joy0;
joy1: dc.b 0 ; volatile byte joy1;
joy2: dc.b 0 ; volatile byte joy2; /* cursor joystick */
last_key: dc.b 0 ; volatile byte last_key;
old_b: dc.b 0 ; last button state
.even
key_interrupt:
move.w d0,-(sp) ;
clr.w d0 ; clear register
move.b $fffffc02.w,d0 ; get scancode
add.w d0,d0 ; verdubbel keycode
move.w .table_start(pc,d0.w),d0; get jump offset
jmp .table_start(pc,d0.w)
.table_start:
dc.w .default-.table_start ;00
dc.w .default-.table_start ;01
dc.w .default-.table_start ;02
dc.w .default-.table_start ;03
dc.w .default-.table_start ;04
dc.w .default-.table_start ;05
dc.w .default-.table_start ;06
dc.w .default-.table_start ;07
dc.w .default-.table_start ;08
dc.w .default-.table_start ;09
dc.w .default-.table_start ;0a
dc.w .default-.table_start ;0b
dc.w .default-.table_start ;0c
dc.w .default-.table_start ;0d
dc.w .default-.table_start ;0e
dc.w .default-.table_start ;0f
dc.w .default-.table_start ;10
dc.w .default-.table_start ;11
dc.w .default-.table_start ;12
dc.w .default-.table_start ;13
dc.w .default-.table_start ;14
dc.w .default-.table_start ;15
dc.w .default-.table_start ;16
dc.w .default-.table_start ;17
dc.w .default-.table_start ;18
dc.w .default-.table_start ;19
dc.w .default-.table_start ;1a
dc.w .default-.table_start ;1b
dc.w .default-.table_start ;1c
dc.w .default-.table_start ;1d
dc.w .default-.table_start ;1e
dc.w .default-.table_start ;1f
dc.w .default-.table_start ;20
dc.w .default-.table_start ;21
dc.w .default-.table_start ;22
dc.w .default-.table_start ;23
dc.w .default-.table_start ;24
dc.w .default-.table_start ;25
dc.w .default-.table_start ;26
dc.w .default-.table_start ;27
dc.w .default-.table_start ;28
dc.w .default-.table_start ;29
dc.w .default-.table_start ;2a
dc.w .default-.table_start ;2b
dc.w .default-.table_start ;2c
dc.w .default-.table_start ;2d
dc.w .default-.table_start ;2e
dc.w .default-.table_start ;2f
dc.w .default-.table_start ;30
dc.w .default-.table_start ;31
dc.w .default-.table_start ;32
dc.w .default-.table_start ;33
dc.w .default-.table_start ;34
dc.w .default-.table_start ;35
dc.w .default-.table_start ;36
dc.w .default-.table_start ;37
dc.w .default-.table_start ;38
dc.w .cur_fire_p-.table_start ;39
dc.w .default-.table_start ;3a
dc.w .default-.table_start ;3b
dc.w .default-.table_start ;3c
dc.w .default-.table_start ;3d
dc.w .default-.table_start ;3e
dc.w .default-.table_start ;3f
dc.w .default-.table_start ;40
dc.w .default-.table_start ;41
dc.w .default-.table_start ;42
dc.w .default-.table_start ;43
dc.w .default-.table_start ;44
dc.w .default-.table_start ;45
dc.w .default-.table_start ;46
dc.w .default-.table_start ;47
dc.w .cur_up_p-.table_start ;48
dc.w .default-.table_start ;49
dc.w .default-.table_start ;4a
dc.w .cur_left_p-.table_start ;4b
dc.w .default-.table_start ;4c
dc.w .cur_right_p-.table_start ;4d
dc.w .default-.table_start ;4e
dc.w .default-.table_start ;4f
dc.w .cur_down_p-.table_start ;50
dc.w .default-.table_start ;51
dc.w .default-.table_start ;52
dc.w .default-.table_start ;53
dc.w .default-.table_start ;54
dc.w .default-.table_start ;55
dc.w .default-.table_start ;56
dc.w .default-.table_start ;57
dc.w .default-.table_start ;58
dc.w .default-.table_start ;59
dc.w .default-.table_start ;5a
dc.w .default-.table_start ;5b
dc.w .default-.table_start ;5c
dc.w .default-.table_start ;5d
dc.w .default-.table_start ;5e
dc.w .default-.table_start ;5f
dc.w .default-.table_start ;60
dc.w .default-.table_start ;61
dc.w .default-.table_start ;62
dc.w .default-.table_start ;63
dc.w .default-.table_start ;64
dc.w .default-.table_start ;65
dc.w .default-.table_start ;66
dc.w .default-.table_start ;67
dc.w .default-.table_start ;68
dc.w .default-.table_start ;69
dc.w .default-.table_start ;6a
dc.w .default-.table_start ;6b
dc.w .default-.table_start ;6c
dc.w .default-.table_start ;6d
dc.w .default-.table_start ;6e
dc.w .default-.table_start ;6f
dc.w .default-.table_start ;70
dc.w .default-.table_start ;71
dc.w .default-.table_start ;72
dc.w .default-.table_start ;73
dc.w .default-.table_start ;74
dc.w .default-.table_start ;75
dc.w .default-.table_start ;76
dc.w .default-.table_start ;77
dc.w .default-.table_start ;78
dc.w .default-.table_start ;79
dc.w .default-.table_start ;7a
dc.w .default-.table_start ;7b
dc.w .default-.table_start ;7c
dc.w .default-.table_start ;7d
dc.w .default-.table_start ;7e
dc.w .default-.table_start ;7f
dc.w .default-.table_start ;80
dc.w .default-.table_start ;81
dc.w .default-.table_start ;82
dc.w .default-.table_start ;83
dc.w .default-.table_start ;84
dc.w .default-.table_start ;85
dc.w .default-.table_start ;86
dc.w .default-.table_start ;87
dc.w .default-.table_start ;88
dc.w .default-.table_start ;89
dc.w .default-.table_start ;8a
dc.w .default-.table_start ;8b
dc.w .default-.table_start ;8c
dc.w .default-.table_start ;8d
dc.w .default-.table_start ;8e
dc.w .default-.table_start ;8f
dc.w .default-.table_start ;90
dc.w .default-.table_start ;91
dc.w .default-.table_start ;92
dc.w .default-.table_start ;93
dc.w .default-.table_start ;94
dc.w .default-.table_start ;95
dc.w .default-.table_start ;96
dc.w .default-.table_start ;97
dc.w .default-.table_start ;98
dc.w .default-.table_start ;99
dc.w .default-.table_start ;9a
dc.w .default-.table_start ;9b
dc.w .default-.table_start ;9c
dc.w .default-.table_start ;9d
dc.w .default-.table_start ;9e
dc.w .default-.table_start ;9f
dc.w .default-.table_start ;a0
dc.w .default-.table_start ;a1
dc.w .default-.table_start ;a2
dc.w .default-.table_start ;a3
dc.w .default-.table_start ;a4
dc.w .default-.table_start ;a5
dc.w .default-.table_start ;a6
dc.w .default-.table_start ;a7
dc.w .default-.table_start ;a8
dc.w .default-.table_start ;a9
dc.w .default-.table_start ;aa
dc.w .default-.table_start ;ab
dc.w .default-.table_start ;ac
dc.w .default-.table_start ;ad
dc.w .default-.table_start ;ae
dc.w .default-.table_start ;af
dc.w .default-.table_start ;b0
dc.w .default-.table_start ;b1
dc.w .default-.table_start ;b2
dc.w .default-.table_start ;b3
dc.w .default-.table_start ;b4
dc.w .default-.table_start ;b5
dc.w .default-.table_start ;b6
dc.w .default-.table_start ;b7
dc.w .default-.table_start ;b8
dc.w .cur_fire_r-.table_start ;b9
dc.w .default-.table_start ;ba
dc.w .default-.table_start ;bb
dc.w .default-.table_start ;bc
dc.w .default-.table_start ;bd
dc.w .default-.table_start ;be
dc.w .default-.table_start ;bf
dc.w .default-.table_start ;c0
dc.w .default-.table_start ;c1
dc.w .default-.table_start ;c2
dc.w .default-.table_start ;c3
dc.w .default-.table_start ;c4
dc.w .default-.table_start ;c5
dc.w .default-.table_start ;c6
dc.w .default-.table_start ;c7
dc.w .cur_up_r-.table_start ;c8
dc.w .default-.table_start ;c9
dc.w .default-.table_start ;ca
dc.w .cur_left_r-.table_start ;cb
dc.w .default-.table_start ;cc
dc.w .cur_right_r-.table_start ;cd
dc.w .default-.table_start ;ce
dc.w .default-.table_start ;cf
dc.w .cur_down_r-.table_start ;d0
dc.w .default-.table_start ;d1
dc.w .default-.table_start ;d2
dc.w .default-.table_start ;d3
dc.w .default-.table_start ;d4
dc.w .default-.table_start ;5d
dc.w .default-.table_start ;d6
dc.w .default-.table_start ;d7
dc.w .default-.table_start ;d8
dc.w .default-.table_start ;d9
dc.w .default-.table_start ;da
dc.w .default-.table_start ;db
dc.w .default-.table_start ;dc
dc.w .default-.table_start ;dd
dc.w .default-.table_start ;de
dc.w .default-.table_start ;df
dc.w .default-.table_start ;e0
dc.w .default-.table_start ;e1
dc.w .default-.table_start ;e2
dc.w .default-.table_start ;e3
dc.w .default-.table_start ;e4
dc.w .default-.table_start ;e5
dc.w .default-.table_start ;e6
dc.w .default-.table_start ;e7
dc.w .default-.table_start ;e8
dc.w .default-.table_start ;e9
dc.w .default-.table_start ;ea
dc.w .default-.table_start ;eb
dc.w .default-.table_start ;ec
dc.w .default-.table_start ;ed
dc.w .default-.table_start ;ee
dc.w .default-.table_start ;ef
dc.w .default-.table_start ;f0
dc.w .default-.table_start ;f1
dc.w .default-.table_start ;f2
dc.w .default-.table_start ;f3
dc.w .default-.table_start ;f4
dc.w .default-.table_start ;f5
dc.w .default-.table_start ;f6
dc.w .default-.table_start ;f7
dc.w .mouse_0-.table_start ;f8
dc.w .mouse_1-.table_start ;f9
dc.w .mouse_2-.table_start ;fa
dc.w .mouse_3-.table_start ;fb
dc.w .default-.table_start ;fc
dc.w .default-.table_start ;fd
dc.w .new_joy0-.table_start ;fe
dc.w .new_joy1-.table_start ;ff
; key action code
.default:
move.b $fffffc02.w,last_key; store last key
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.new_joy0:
move.l #.get_joy0,$118.w
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.new_joy1:
move.l #.get_joy1,$118.w
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.mouse_0:
clr.b buttons ; no buttons
move.l #.get_mouse_x,$118.w; get mouse_x
move.w (sp)+,d0
move.b #$bf,$fffffa11.w
rte
.mouse_1:
move.b #1,buttons ; right button
move.l #.get_mouse_x,$118.w; get mouse_x
move.w (sp)+,d0
move.b #$bf,$fffffa11.w
rte
.mouse_2:
move.b #2,buttons ; left button
move.l #.get_mouse_x,$118.w; get mouse_x
move.w (sp)+,d0
move.b #$bf,$fffffa11.w
rte
.mouse_3:
move.b #3,buttons ; both buttons
move.l #.get_mouse_x,$118.w; get mouse_x
move.w (sp)+,d0
move.b #$bf,$fffffa11.w
rte
.get_joy0:
move.b $fffffc02.w,joy0 ; get joy0 status
move.l #key_interrupt,$118.w
move.b #$bf,$fffffa11.w
rte ; done
.get_joy1:
move.b $fffffc02.w,joy1 ; get joy1 status
move.l #key_interrupt,$118.w
move.b #$bf,$fffffa11.w
rte ; done
.get_mouse_x:
move.w d0,-(sp)
clr.w d0
move.b $fffffc02.w,d0 ; coordinate
ext.w d0
add.w mouse_x(pc),d0 ; new mouse_x
bge.s .mouse_x_max
clr.w d0
bra.s .mouse_x_done
.mouse_x_max:
cmp.w #MOUSE_X_MAX,d0
ble.s .mouse_x_done
move.w #MOUSE_X_MAX,d0
.mouse_x_done:
move.w d0,mouse_x
move.l #.get_mouse_y,$118.w; get mouse_y
move.w (sp)+,d0
move.b #$bf,$fffffa11.w
rte
.get_mouse_y:
move.l #key_interrupt,$118.w;
move.w d0,-(sp)
move.l a0,-(sp)
lea old_b(pc),a0
clr.w d0
move.b $fffffc02.w,d0 ; coordinate
ext.w d0
add.w mouse_y-old_b(a0),d0 ; new mouse_y
bge.s .mouse_y_max
clr.w d0
bra.s .mouse_ytest_done
.mouse_y_max:
cmp.w #MOUSE_Y_MAX,d0
ble.s .mouse_ytest_done
move.w #MOUSE_Y_MAX,d0
.mouse_ytest_done:
move.w d0,mouse_y-old_b(a0)
clr.w d0
move.b (a0),d0 ; old button state
add.w d0,d0
add.w d0,d0
or.b buttons-old_b(a0),d0
move.b buttons-old_b(a0),(a0)
move.b .click_tab(d0.w,pc),d0 ; is there a click?
beq.s .mouse_y_done
move.b d0,click_f-old_b(a0) ; set click flag
move.w mouse_x-old_b(a0),click_x-old_b(a0)
move.w mouse_y-old_b(a0),click_y-old_b(a0)
.mouse_y_done:
move.l (sp)+,a0
move.w (sp)+,d0
move.b #$bf,$fffffa11.w
rte
.click_tab:
dc.b 0,1,2,3,0,0,2,2,0,1,0,1,0,0,0,0 ; click table
.cur_up_p:
or.b #JOY_UP,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_up_r:
and.b #!JOY_UP,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_left_p:
or.b #JOY_LEFT,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_left_r:
and.b #!JOY_LEFT,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_right_p:
or.b #JOY_RIGHT,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_right_r:
and.b #!JOY_RIGHT,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_down_p:
or.b #JOY_DOWN,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_down_r:
and.b #!JOY_DOWN,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_fire_p:
or.b #JOY_FIRE,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
.cur_fire_r:
and.b #$7f,joy2
move.w (sp)+,d0 ; restore registers
move.b #$bf,$fffffa11.w
rte ; done
initmuis: ; preshift muis data
move.l d3,-(sp)
lea muisdata(pc),a0
lea muispreshift+(15*256)+16,a1
moveq #15,d0
.lineloop:
moveq #-1,d1
moveq #0,d2
move.w (a0)+,d1 ; mask
move.w (a0)+,d2 ; data
moveq #15,d3
.shiftloop:
add.l d1,d1
addq.w #1,d1
add.l d2,d2
move.w d2,-(a1)
move.w d2,-(a1)
move.w d1,-(a1)
move.w d1,-(a1)
swap d2
swap d1
move.w d2,-(a1)
move.w d2,-(a1)
move.w d1,-(a1)
move.w d1,-(a1)
swap d2
swap d1
lea -256+16(a1),a1
dbra d3,.shiftloop
lea (16*256)+16(a1),a1
dbra d0,.lineloop
move.l (sp)+,d3
rts
hidemuis:
lea muisbuffer,a0
move.l (a0)+,a1
move.w (a0)+,d0 ; lines
move.w (a0)+,d1 ; words
bne.s .singlelong
movem.l d3-d4,-(sp)
.lineloop0:
movem.l (a0)+,d1-d4
movem.l d1-d4,(a1)
lea 160(a1),a1
dbra d0,.lineloop0
movem.l (sp)+,d3-d4
rts
.singlelong:
.lineloop1:
move.l (a0)+,(a1)+
move.l (a0)+,(a1)+
lea 160-8(a1),a1
dbra d0,.lineloop1
rts
; d0.w x
; d1.w y
; a0 screen
showmuis:
movem.l d3-d6/a2,-(sp)
move.w #MOUSE_Y_MAX,d2
sub.w d1,d2 ; lines
cmp.w #15,d2 ; #lines
bls.s .nolinefix
moveq #15,d2 ; max 16 lines
.nolinefix:
mulu #160,d1 ; y-offset
moveq #-16,d3
and.w d0,d3
lsr.w #1,d3 ; x-offset
add.w d1,d3 ; offset muisdata
lea 0(d3.w,a0),a0
lea muisbuffer,a1
move.l a0,(a1)+
move.w d2,(a1)+
cmp.w #MOUSE_X_MAX-16,d0
bgt.s .singleword
clr.w (a1)+
move.w d2,d1
move.l a0,a2
.lineloop0:
movem.l (a2),d3-d6
movem.l d3-d6,(a1)
lea 160(a2),a2
lea 16(a1),a1
dbra d2,.lineloop0
and.w #$f,d0
lsl.w #8,d0 ; offset in preshiftdata
lea muispreshift,a1
add.w d0,a1
.tekenloop0:
movem.l (a1)+,d2/d3/d4/d5
move.l (a0)+,d0
and.l d2,d0
or.l d3,d0
and.l (a0)+,d2
or.l d3,d2
move.l (a0)+,d3
and.l d4,d3
or.l d5,d3
and.l (a0)+,d4
or.l d5,d4
movem.l d0/d2-d4,-(a0)
lea 160(a0),a0
dbra d1,.tekenloop0
movem.l (sp)+,d3-d6/a2
rts
.singleword:
move.w d0,(a1)+ ; set word flag
move.w d2,d1
move.l a0,a2
.lineloop1:
move.l (a2)+,(a1)+
move.l (a2)+,(a1)+
lea 160-8(a2),a2
dbra d2,.lineloop1
and.w #$f,d0
lsl.w #8,d0 ; offset in preshiftdata
lea muispreshift,a1
add.w d0,a1
.tekenloop1:
move.l (a1)+,d2
move.l (a1)+,d3
move.l (a0)+,d0
and.l d2,d0
or.l d3,d0
and.l (a0)+,d2
or.l d3,d2
movem.l d0/d2,-(a0)
lea 160(a0),a0
addq.l #8,a1
dbra d1,.tekenloop1
movem.l (sp)+,d3-d6/a2
rts
muisdata:
dc.b 63,255,0,0,31,255,64,0,15,255,96,0,7,255,112,0
dc.b 3,255,120,0,1,255,124,0,0,255,126,0,0,127,127,0
dc.b 0,63,127,128,0,31,124,0,1,255,108,0,16,255,70,0
dc.b 48,255,6,0,120,127,3,0,248,127,3,0,248,127,0,0
BSS
muisbuffer:
ds.l 1 ; screenpos of mouse data
ds.w 1 ; # lines
ds.w 1 ; 1 word?
ds.b 16*16 ; schermdata
muispreshift:
ds.b 16*256 ; mask mask data data mask mask data data; newline