Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
alexbevi
GitHub Repository: alexbevi/BizHawk
Path: blob/master/yabause/src/dreamcast/sh2rec/sh2exec.s
2 views
1
! Copyright 2010 Lawrence Sebald
2
!
3
! This file is part of Yabause.
4
!
5
! Yabause is free software; you can redistribute it and/or modify
6
! it under the terms of the GNU General Public License as published by
7
! the Free Software Foundation; either version 2 of the License, or
8
! (at your option) any later version.
9
!
10
! Yabause is distributed in the hope that it will be useful,
11
! but WITHOUT ANY WARRANTY; without even the implied warranty of
12
! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
! GNU General Public License for more details.
14
!
15
! You should have received a copy of the GNU General Public License
16
! along with Yabause; if not, write to the Free Software
17
! Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18
19
! Code for calling upon the code generated by sh2rec (SuperH).
20
21
.file "sh2exec.s"
22
.little
23
.text
24
.balign 8
25
26
! void sh2rec_exec(SH2_struct *cxt, u32 cycles)
27
! Execute the specified number of cycles on the given SH2 context
28
.globl _sh2rec_exec
29
_sh2rec_exec:
30
stc.l gbr, @-r15 ! Save call-preserved stuff
31
sts.l mach, @-r15 ! Ditto
32
sts.l macl, @-r15 ! Ditto
33
mov.l r8, @-r15 ! Ditto
34
mov r4, r8 ! Put the SH2 struct in r8
35
mov.l r9, @-r15 ! More call-preserved stuff
36
add #76, r4 ! Point at MACH in the SH2 struct
37
mov.l r10, @-r15 ! More call-preserved stuff
38
mov.l r11, @-r15 ! Last one for now...
39
lds.l @r4+, mach ! Load the SH2 MACH into our MACH
40
lds.l @r4+, macl ! Ditto for MACL
41
mov.l checkInterrupts, r0 ! We need to check for interrupts...
42
mov.l sh2memfuncsptr, r9 ! Memory access function pointer table
43
sts.l pr, @-r15 ! Helps to know where to go back to
44
mov r5, r11 ! This is important enough to keep here
45
mov.l r5, @-r15 ! Save this on the stack too
46
mov r8, r4 ! We need the original SH2_struct back
47
jsr @r0 ! Call sh2rec_check_interrupts
48
ldc r8, gbr ! Put the SH2 struct in gbr (delay slot)
49
mov.l findBlock, r1 ! Grab the sh2rec_find_block function
50
mov.l @(88, gbr), r0 ! Grab the PC we are at
51
.exec_loop: ! This is where the fun is!
52
jsr @r1 ! Call sh2rec_find_block
53
mov r0, r4 ! Move the PC to argument 1 (delay slot)
54
mov.l @r0, r2 ! Grab where the code is
55
mov.l @(8, r0), r1 ! Figure out the number of cycles used
56
jsr @r2 ! Call the block
57
sub r1, r11 ! Chop off the cycles (delay slot)
58
cmp/pl r11 ! Are we done?
59
mov.l findBlock, r1 ! Grab the sh2rec_find_block function
60
bt .exec_loop ! Continue on if needed
61
! When we are done, we will be here.
62
mov.l r0, @(88, gbr) ! Save the next PC value
63
mov.l @r15+, r5 ! Pop the requested number of cycles
64
mov r8, r4 ! Keep this for sanity for now
65
add #84, r8 ! Point just after MACL in SH2 struct
66
sts.l macl, @-r8 ! Store the SH2 MACL back in the struct
67
sts.l mach, @-r8 ! Ditto for MACH
68
lds.l @r15+, pr ! Restore stuff from the stack
69
sub r11, r5 ! Our counter is negitive, so this works
70
mov.l cycleOffset, r2 ! Where is the cycles member at?
71
mov.l @r15+, r11 ! More restoring...
72
add r2, r4 ! Point r4 at the cycles member
73
mov.l @r15+, r10
74
mov.l @r15+, r9
75
mov.l @r15+, r8
76
lds.l @r15+, macl
77
lds.l @r15+, mach
78
mov.l r5, @r4 ! Save the cycles we spent
79
rts ! Return to the caller
80
ldc.l @r15+, gbr ! Last thing to restore (delay slot)
81
82
.balign 4
83
sh2memfuncsptr:
84
.long sh2memfuncs
85
checkInterrupts:
86
.long _sh2rec_check_interrupts
87
findBlock:
88
.long _sh2rec_find_block
89
cycleOffset:
90
.long 5516
91
92
.data
93
.balign 4
94
sh2memfuncs:
95
.long _MappedMemoryReadByte
96
.long _MappedMemoryReadWord
97
.long _MappedMemoryReadLong
98
.long _MappedMemoryWriteByte
99
.long _MappedMemoryWriteWord
100
.long _MappedMemoryWriteLong
101
102