Skip to content

Commit

Permalink
Bug fixes and started work on RNG
Browse files Browse the repository at this point in the history
  • Loading branch information
Quantumdit committed Apr 3, 2017
1 parent 0b003ee commit fb11b74
Show file tree
Hide file tree
Showing 4 changed files with 82 additions and 15 deletions.
31 changes: 19 additions & 12 deletions templateUART/InterruptCode/InterruptHandler.s
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
//Usage: Should be the first instruction in the program
InitInterrupts:
push {r4-r10, lr} //Push registers onto stack
bl InstallIntTable //Install the interrupt tabel
bl EnableIRQ //Enable IRQ interrupt
bl InstallIntTable //Install the interrupt tabel
bl EnableIRQ //Enable IRQ interrupt
pop {r4-r10, pc} //Pop registers from stack

//Input: null
Expand Down Expand Up @@ -49,8 +49,8 @@ _InstallIntTable:
//Input: null
//Output: null
//Effect: enables IRQ
_EnableIRQ:
push {r4-r10, lr} //Push registers onto stack
_f_EnableIRQ:
push {r4-r10, lr} //Push registers onto stack

//a Update timer value
ldr r4, =0x20003004 //Load address of CLO
Expand All @@ -73,14 +73,14 @@ _EnableIRQ:
str r1, [r0] //Store the value of r1 in r0
//d. For cpsr_c register
//cpsr_c is not defined/equated anywhere. Gonna have to disable this code -SK
mrs r0, cpscr //mrs r0,cpscr
bic r0, #0x80 //bic r0, #0x80
msr cpsr_c, r0 //msr cpsr_c, r0
mrs r0, cpscr //mrs r0,cpscr
bic r0, #0x80 //bic r0, #0x80
msr cpsr_c, r0 //msr cpsr_c, r0

pop {r4-r10, pc} //Pop register from the stack
pop {r4-r10, pc} //Pop register from the stack

_Doirq:
push {r4-r10, lr} //Push registers from the stack
_f_DoIRQ:
push {r4-r10, lr} //Push registers from the stack

// a. Test if timer1 did the interrupt
// i. Load the values stored in 0x3F00B204 to r1
Expand Down Expand Up @@ -108,10 +108,17 @@ _Doirq:
mov r6, #2
str r6, [r4] //Not sure if this should be [r4] or [r5]
// e. Update time in C1

e:
ldr r4, =0x20003004 //Load address of CLO
ldr r5, [r4] //Load CLO
ldr r6, =30000000 //Load the number 30 million
add r5, r6 //Add a delay of 30 million microseconds (30 seconds)
add r4, #12 //Add 12 to get to timer compare 1
str r5, [r4] //Store the address
// f. Repeat (2)
bl _f_DoIRQ
// g. Then subs pc, lr, #4
subs pc, lr, #4

pop {r4-r10, pc} //Pop register from the stack

Expand All @@ -134,5 +141,5 @@ swi_handler: .word hang
prefetch_handler: .word hang
data_handler: .word hang
unused_handler: .word hang
irq_handler: .word _Doirq
irq_handler: .word _f_DoIRQ
fiq_handler: .word hang
5 changes: 2 additions & 3 deletions templateUART/source/Mario.s
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@ f_resetMarioPosition:
//Clear Mario from the map
ldr r4, =_d_marioPositionX //Store the address of Mario's current X position
ldr r5, =_d_marioPositionY //Store the address of Mario's current Y posiion
ldr r6, =d_mapForeground //Load the address of the foreground
ldrh r0, [r4] //Load Mario's current X position
ldrh r1, [r5] //Load Mario's current Y position
mov r2, r6 //Move in the address of the foreground
mov r2, =d_mapForeground //Move in the address of the foreground
mov r3, #0 //Load the code for an empty cell
bl f_setCellElement //Replace Mario with an empty cell

Expand All @@ -40,7 +39,7 @@ f_resetMarioPosition:
//Add Mario to his default location on the map
mov r0, r7 //Move in Mario's default X position
mov r1, r8 //Move in Mario's default Y position
mov r2, r6 //Move in the address of the foreground
mov r2, =d_mapForeground //Move in the address of the foreground
mov r3, #0 //Load the code for an empty cell
bl f_setCellElement //Replace Mario with an empty cell

Expand Down
1 change: 1 addition & 0 deletions templateUART/source/PauseMenu.s
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ _f_drawSelection:
bl f_drawElement

_drawSelectionEnd:
bl f_refreshScreen


pop {pc} //Return to caller popping pc
Expand Down
60 changes: 60 additions & 0 deletions templateUART/source/ValuePack.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
//This file handles the value pack

.section .init

.section .text


//Input: Null
//Output: Random number in r0
//Effect: Null
// Random Generator Function (No need for Parameters):
_f_RNG:
// Push r4 to r8 ( you need 5 registers for x,y,z,w and t)
push {r4-r8, lr} //Push registers to the stack

//r4 = t
//r5 = w
//r6 = x
//r7 = y
//r8 = z

// load x,y,z,and w integer values from memory
ldr r4, =_d_w
ldr r5, [r4]
ldr r4, =_d_x
ldr r6, [r4]
ldr r4, =_d_y
ldr r7, [r4]
ldr r4, =_d_z
ldr r8, [r4]
// move x to t
mov r4, r6
// xor t by using the following instruction (eor t, t, t, lsl #11)
eor r4, r4, r4, lsl #11
// xor it again using 8 instead of 11
eor r4, r4, r4, lsl #8
// move y to x
mov r6, r7
// move z to y
mov r7, r8
// move w to z
mov r8, r5
// then xor w (eor t, t, t, lsl #19)
// xor w with t
// then store value of x in its place in memory( do the same for y z and w)
// This is made so that they are updated every time and to make it randomly and not every time is based on their initialized
// return w as the returned value

pop {r4-r8, pc} //Pop register from the stack and return

.section .data

// Create 4 labels in the data section each having an integer value
// example: x: .int 5000
// Make sure the number you chose is less than 2^64
// You should create labels for y, z and w each with different integer value
_d_w: .int 1605
_d_x: .int 8201
_d_y: .int 3955
_d_z: .int 9602

0 comments on commit fb11b74

Please sign in to comment.