Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- arch snes.cpu
- //*****************************************************
- //*
- //* mouse.x65
- //* Super NES Mouse System file
- //* March 11, 1992
- //* (c) 1992 Nintendo of America
- //*
- //* mouse_v100_bass.asm
- //* December 18, 2016
- //* Modified by LuigiBlood for bass
- //*
- //*****************************************************
- //*****************************************************
- //*****************************************************
- //* Mouse Driver Routine (Ver 1.00)
- //*****************************************************
- //*****************************************************
- db "START OF MOUSE BIOS" //do not delete
- //=====================================================
- //* RAM Definition
- //=====================================================
- //Change this to the address you want
- define MouseVars $0000
- define reg0 {MouseVars}+0
- define reg0l {reg0}+0 // Work registers
- define reg0h {reg0}+1 //
- define mouse_con {MouseVars}+2
- define mouse_con0 {mouse_con}+0 // Mouse connection port D0=4016
- define mouse_con1 {mouse_con}+1 // Mouse connection port D0=4017
- define mouse_sp_set {MouseVars}+4
- define mouse_sp_set0 {mouse_sp_set}+0 // Mouse speed setting (joy1)
- define mouse_sp_set1 {mouse_sp_set}+1 // Mouse speed setting (joy2)
- define mouse_sp {MouseVars}+6
- define mouse_sp0 {mouse_sp}+0 // Mouse speed (joy1)
- define mouse_sp1 {mouse_sp}+1 // Mouse speed (joy2)
- define mouse_y0 {MouseVars}+8 // Mouse Y direction (joy 1)
- define mouse_y1 {MouseVars}+9 // Mouse Y direction (joy 2)
- define mouse_x0 {MouseVars}+10 // Mouse X direction (joy 1)
- define mouse_x1 {MouseVars}+11 // Mouse X direction (joy 2)
- define mouse_sw {MouseVars}+12
- define mouse_sw0 {mouse_sw}+0 // Mouse button turbo (joy1)
- define mouse_sw1 {mouse_sw}+1 // Mouse button turbo (joy2)
- define mouse_swt {MouseVars}+14
- define mouse_swt0 {mouse_swt}+0 // Mouse button trigger (joy1)
- define mouse_swt1 {mouse_swt}+1 // Mouse button trigger (joy2)
- define mouse_sb {MouseVars}+16 // Previous switch status
- define mouse_sb0 {mouse_sb}+0 //
- define mouse_sb1 {mouse_sb}+1
- define connect_st0 {MouseVars}+18 // Mouse is connected? (joy1)
- define connect_st1 {MouseVars}+19 // Mouse is connected? (joy2)
- define cursor_x0 {MouseVars}+20 //Cursor X position (joy1)
- define cursor_x1 {MouseVars}+22 //Cursor X position (joy2)
- define cursor_y0 {MouseVars}+24 //Cursor Y position (joy1)
- define cursor_y1 {MouseVars}+26 //Cursor Y position (joy2)
- //*****************************************************
- //=====================================================
- //* mouse_read
- //=====================================================
- //* If this routine is called every frame, then the mouse status will be set to the
- //* appropriate registers.
- //* INPUT
- //* None (Mouse key read automatically)
- //* OUTPUT
- //* Connection status (mouse_con) D0=1 Mouse connected to Joy1
- //* D1=1 Mouse connected to Joy2
- //* Switch (mouse_sw0,1) D0=left switch turbo
- //* D1=right switch turbo
- //* Switch (mouse_swt0,1) D0=left switch trigger
- //* D1=right switch trigger
- //* Mouse movement (ball) value
- //* (mouse_x) D7=0 Positive turn, D7=1 Negative turn
- //* D6-D0 X movement value
- //* (mouse_y) D7=0 Positive turn, D7=1 Negative turn
- //* D6-D0 X movement value
- //*****************************************************
- mouse_read:
- php
- sep #$30
- _10:
- lda $4212
- and.b #%00000001
- bne _10 // Automatic read ok?
- ldx.b #$01 // Joy2
- lda $421a
- jsr mouse_data
- lda {connect_st1}
- beq _20
- jsr speed_change
- stz {connect_st1}
- plp
- rts
- _20:
- dex
- lda $4218 // joy1
- jsr mouse_data
- lda {connect_st0}
- beq _30
- jsr speed_change
- stz {connect_st0}
- _30:
- plp
- rts
- mouse_data:
- sta {reg0l} //(421a 4218 save to reg0)
- and.b #%00001111
- cmp.b #$01 // Is the mouse connected?
- beq _m10
- stz {mouse_con0},x // No connection.
- stz {mouse_x0},x
- stz {mouse_y0},x
- stz {mouse_sw0},x
- stz {mouse_swt0},x
- stz {mouse_sb0},x
- rts
- _m10:
- lda {mouse_con0},x // When mouse is connected, speed will change.
- bne _m20 // Previous connection status
- // (mouse.com judged by lower 1 bit)
- lda.b #$01 // Connection check flag on
- sta {mouse_con0},x
- sta {connect_st0},x
- rts
- _m20:
- ldy.b #16 // Read 16 bit data.
- _m30:
- lda $4016,x
- lsr
- rol {mouse_x0},x
- rol {mouse_y0},x
- dey
- bne _m30
- stz {mouse_sw0},x
- rol {reg0l}
- rol {mouse_sw0},x
- rol {reg0l}
- rol {mouse_sw0},x // Switch turbo
- lda {mouse_sw0},x
- eor {mouse_sb0},x // Get switch trigger
- bne _m40
- stz {mouse_swt0},x
- rts
- _m40:
- lda {mouse_sw0},x
- sta {mouse_swt0},x
- sta {mouse_sb0},x
- rts
- //*****************************************************
- //=====================================================
- //* speed_change
- //=====================================================
- //* Set speed to mouse_sp_set. Give mouse port the value of x and call this routine.
- //* If this routine is called without setting mouse_sp_set, then the previous speed will be assigned to the current speed.
- //* Normally, the mouse speed data will be saved to mouse_sp.
- //* If the mouse speed cannot be set, then the error code will be set to mouse_sp.
- //* INPUT
- //* X=connection port (X:0=joy1 1=joy2)
- //* MOUSE_SP_SET0= JOY1 setting speed
- //* MOUSE_SP_SET1= JOY2 setting speed
- //* OUTPUT
- //* MOUSE_SP0 = Joy1 Mouse speed
- //* (0=slow, 1=medium, 2=fast, $80=error code)
- //* MOUSE_SP1 = Joy2 Mouse speed
- //* (0=slow, 1=medium, 2=fast, $80=error code)
- //*****************************************************
- speed_change:
- php
- sep #$30
- lda {mouse_con},x
- beq _s25
- lda.b #$10
- sta {reg0h}
- _s10:
- lda.b #$01
- sta $4016
- lda $4016,x // Speed change (1 step).
- stz $4016
- lda.b #$01 // Read speed data.
- sta $4016 // Shift register clear.
- lda.b #$00
- sta $4016
- sta {mouse_sp0},x // Speed register clear.
- ldy.b #$0a // Shift register read has no meaning.
- _s20:
- lda $4016,x
- dey
- bne _s20
- lda $4016,x // Read speed
- lsr
- rol {mouse_sp0},x
- lda $4016,x
- lsr
- rol {mouse_sp0},x
- lda {mouse_sp0},x
- cmp {mouse_sp_set0},x //Set speed or not?
- beq _s30
- dec {reg0h} // For error check
- bne _s10
- _s25:
- lda #$80 // Speed change error
- sta {mouse_sp0},x
- _s30:
- plp
- rts
- //*****************************************************
- //=====================================================
- //* cursor_update
- //=====================================================
- //* Call this routine after mouse_read, calculates the cursor position.
- //* Use the position as cursor coordinates.
- //* Minimum and Maximum X and Y positions are set by min_x,y and max_x,y.
- //* Based on Sound Factory prototype mouse code.
- //* Destroys the data of A and Y.
- //*
- //* INPUT
- //* X=connection port (X:0=joy1 1=joy2)
- //* OUTPUT
- //* Cursor X Position (cursor_x0,1)
- //* Cursor Y Position (cursor_y0,1)
- //*****************************************************
- define min_x #$0001 //Minimum X position
- define min_y #$0001 //Minimum Y position
- define max_x #$00F4 //Maximum X position
- define max_y #$00D6 //Maximum Y position
- cursor_update:
- php
- sep #$30
- txa
- rol
- tay
- _xcursor:
- sep #$20
- lda {mouse_x0},x
- bmi _xcursor_minus
- xba
- lda.b #$00
- bra _xcursor_check
- _xcursor_minus:
- eor.b #$7f
- inc
- xba
- lda.b #$ff
- _xcursor_check:
- xba
- rep #$20
- clc
- adc {cursor_x0},y
- bpl _xcursorpos_greater
- lda #$0000
- _xcursorpos_greater:
- cmp {max_x}
- bcc _xcursorpos_lower
- lda {max_x}-1
- _xcursorpos_lower:
- cmp {min_x}
- bcs _xcursor_update
- lda {min_x}+1
- _xcursor_update:
- sta {cursor_x0},y
- _ycursor:
- sep #$20
- lda {mouse_y0},x
- bmi _ycursor_minus
- xba
- lda.b #$00
- bra _ycursor_check
- _ycursor_minus:
- eor.b #$7f
- inc
- xba
- lda.b #$ff
- _ycursor_check:
- xba
- rep #$20
- clc
- adc {cursor_y0},y
- bpl _ycursorpos_greater
- lda #$0000
- _ycursorpos_greater:
- cmp {max_y}
- bcc _ycursorpos_lower
- lda {max_y}-1
- _ycursorpos_lower:
- cmp {min_y}
- bcs _ycursor_update
- lda {min_y}+1
- _ycursor_update:
- sta {cursor_y0},y
- plp
- rts
- //db "NINTENDO SNES MOUSE BIOS Ver1.00"
- db "BASS MODIFIED FROM SNES MOUSE BIOS Ver1.00"
- //If user modifies program, then change to
- //"MODIFIED FROM SNES MOUSE BIOS Ver1.00"
- db "END OF MOUSE BIOS"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement