aboutsummaryrefslogtreecommitdiff
path: root/libpcsxcore/ppc/pasm.s
blob: 96891b428a4b7d041ab834eeed3acfd23e2747f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#define OLD_REGISTER_OFFSET	(19*4)
#define SP_SIZE			(OLD_REGISTER_OFFSET+4+8)

/*asm void recRun(register void (*func)(), register u32 hw1, register u32 hw2)*/
        .text
        .align  4
        .globl  recRun
recRun:
	/* prologue code */
	mflr	r0
	stmw	r13, -(32-13)*4(r1)
	stw		r0, 4(r1)
	stwu	r1, -((32-13)*4+8)(r1)
	
	/* execute code */
	mtctr	r3
	mr	r31, r4
	mr	r30, r5
	bctrl
/*
}
asm void returnPC()
{*/
        .text
        .align  4
        .globl  returnPC
returnPC:
	// end code
	lwz		r0, (32-13)*4+8+4(r1)
	addi	r1, r1, (32-13)*4+8
	mtlr	r0
	lmw		r13, -(32-13)*4(r1)
	blr
//}*/

// Memory functions that only works with a linear memory

        .text
        .align  4
        .globl  dynMemRead8
dynMemRead8:
// assumes that memory pointer is in r30
	addis    r2,r3,-0x1f80
	srwi.     r4,r2,16
	bne+     .norm8
	cmplwi   r2,0x1000
	blt-     .norm8
	b        psxHwRead8
.norm8:
	clrlwi   r5,r3,3
	lbzx     r3,r5,r30
	blr

        .text
        .align  4
        .globl  dynMemRead16
dynMemRead16:
// assumes that memory pointer is in r30
	addis    r2,r3,-0x1f80
	srwi.     r4,r2,16
	bne+     .norm16
	cmplwi   r2,0x1000
	blt-     .norm16
	b        psxHwRead16
.norm16:
	clrlwi   r5,r3,3
	lhbrx    r3,r5,r30
	blr

        .text
        .align  4
        .globl  dynMemRead32
dynMemRead32:
// assumes that memory pointer is in r30
	addis    r2,r3,-0x1f80
	srwi.     r4,r2,16
	bne+     .norm32
	cmplwi   r2,0x1000
	blt-     .norm32
	b        psxHwRead32
.norm32:
	clrlwi   r5,r3,3
	lwbrx    r3,r5,r30
	blr

/*
	N P Z
	0 0 0 X
-	0 0 1 X
	1 0 0 X
	1 0 1 X

P | (!N & Z)
P | !(N | !Z)
*/

        .text
        .align  4
        .globl  dynMemWrite32
dynMemWrite32:
// assumes that memory pointer is in r30
	addis    r2,r3,-0x1f80
	srwi.    r5,r2,16
	bne+     .normw32
	cmplwi   r2,0x1000
	blt      .normw32
	b        psxHwWrite32
.normw32:
	mtcrf    0xFF, r3
	clrlwi   r5,r3,3
	crandc   0, 2, 0
	cror     2, 1, 0
	bne+     .okw32
	// write test
	li			r2,0x0130
	addis    r2,r2,0xfffe
	cmplw    r3,r2
	bnelr
.okw32:
	stwbrx   r4,r5,r30
	blr