Offloaded some NES routines to eznes.h
This commit is contained in:
+14
-14
@@ -52,7 +52,7 @@ void ppu_on() {
|
||||
PPU.mask |= 0x1A;
|
||||
}
|
||||
|
||||
int joy_input_wait() {
|
||||
u8 joy_input_wait() {
|
||||
u8 last_joy = 0, joy, pressed;
|
||||
/* wait until the previous key is released */
|
||||
while(joy_read(JOY_1));
|
||||
@@ -88,7 +88,7 @@ void init_palette(u8 bg, u8 c1, u8 c2, u8 c3, u8 c4) {
|
||||
|
||||
/* 4x4 char block colorization method (palette is 0 to 3) */
|
||||
void colorxy(u8 x, u8 y, u8 palette) {
|
||||
unsigned int addr;
|
||||
u16 addr;
|
||||
u8 attr_byte;
|
||||
addr = 0x23C0 + ((y >> 2) << 3) + (x >> 2);
|
||||
attr_byte = palette | (palette << 2) | (palette << 4) | (palette << 6);
|
||||
@@ -100,25 +100,25 @@ void colorxy(u8 x, u8 y, u8 palette) {
|
||||
|
||||
/* Sound section */
|
||||
|
||||
unsigned int get_timer_by_freq(int freq) {
|
||||
return (unsigned int) ((CPU / 16 / freq) - 1);
|
||||
u16 get_timer_by_freq(u16 freq) {
|
||||
return (u16) ((CPU / 16 / freq) - 1);
|
||||
}
|
||||
|
||||
void play_pulse(u8 idx, unsigned int freq, u8 len) {
|
||||
unsigned int tm = get_timer_by_freq(freq);
|
||||
void play_pulse(u8 idx, u16 freq, u8 len) {
|
||||
u16 tm = get_timer_by_freq(freq);
|
||||
if(len > 31) len = 31;
|
||||
if(idx > 1) idx = 0;
|
||||
APU.pulse[idx].period_low = tm & 255;
|
||||
APU.pulse[idx].len_period_high = (tm >> 8) | (len << 3);
|
||||
}
|
||||
|
||||
void play_jingle(unsigned int n1f1,
|
||||
unsigned int n1f2,
|
||||
unsigned int n2f1,
|
||||
unsigned int n2f2,
|
||||
unsigned int n3f1,
|
||||
unsigned int n3f2) {
|
||||
unsigned int i, dl = 2000;
|
||||
void play_jingle(u16 n1f1,
|
||||
u16 n1f2,
|
||||
u16 n2f1,
|
||||
u16 n2f2,
|
||||
u16 n3f1,
|
||||
u16 n3f2) {
|
||||
u16 i, dl = 2000;
|
||||
play_pulse(0, n1f1, 2);
|
||||
play_pulse(1, n1f2, 2);
|
||||
for(i=0;i<dl;++i);
|
||||
@@ -165,7 +165,7 @@ void wait_for_start() {
|
||||
/* randomize until Start is pressed */
|
||||
void wait_for_start_rand() {
|
||||
u8 joy;
|
||||
unsigned int entropy = rand();
|
||||
u16 entropy = rand();
|
||||
while(1) {
|
||||
++entropy;
|
||||
joy = joy_read(JOY_1);
|
||||
|
||||
+10
-11
@@ -155,13 +155,14 @@ static char deck[44], room[] = {0, 0, 0, 0};
|
||||
static char status_msg[(SCREEN_WIDTH-1)];
|
||||
|
||||
/* tracking variables */
|
||||
static s16 deck_idx = 0, hp = 20, rooms_cleared = 0,
|
||||
static s16 hp = 20;
|
||||
static u8 deck_idx = 0, rooms_cleared = 0,
|
||||
weapon = 0, durability = 0, can_run = 1,
|
||||
engaged = 0, potion_drank = 0, last_potion_val = 0;
|
||||
|
||||
/* Input method */
|
||||
/* up 1, left 2, right 3, down 4, a run, start quit */
|
||||
char get_choice() {
|
||||
u8 get_choice() {
|
||||
switch(joy_input_wait()) {
|
||||
case EZJOY_UP: return CH1;
|
||||
case EZJOY_LT: return CH2;
|
||||
@@ -173,10 +174,8 @@ char get_choice() {
|
||||
}
|
||||
|
||||
/* Draw a room character according to the index and value */
|
||||
void render_room_item(s16 i, s16 v) {
|
||||
u8 color,
|
||||
topleft_x, topleft_y,
|
||||
topright_x, bottomleft_y,
|
||||
void render_room_item(u8 i, u8 v) {
|
||||
u8 color, topleft_x, topleft_y, topright_x, bottomleft_y,
|
||||
text_x, text_y, cheight=7, cwidth=8, left_offset = 9;
|
||||
if(i == 0) {
|
||||
topleft_x = 8;
|
||||
@@ -300,7 +299,7 @@ void print_msg(char *s) {
|
||||
}
|
||||
|
||||
/* Array shuffle method */
|
||||
void shuffle(char *array, u16 n) {
|
||||
void shuffle(s8 *array, u16 n) {
|
||||
u16 i, j, t;
|
||||
if(n > 1) {
|
||||
for(i=n-1;i>0;i--) {
|
||||
@@ -338,7 +337,7 @@ s16 handle_monster(s16 val) {
|
||||
return val;
|
||||
}
|
||||
|
||||
void handle_weapon(s16 val) {
|
||||
void handle_weapon(u8 val) {
|
||||
weapon = val;
|
||||
snprintf(status_msg, sizeof(status_msg), "You equip a %d-level weapon.", weapon);
|
||||
durability = 14; /* reset durability to max limit */
|
||||
@@ -366,7 +365,7 @@ s16 game() {
|
||||
s16 score = -208; /* score storage */
|
||||
s16 item, room_sum; /* true item value */
|
||||
s16 last_room = 0, last_room_clr = 0; /* last room markers */
|
||||
char ch;
|
||||
u8 ch;
|
||||
deck_idx = 0; /* reset the deck index */
|
||||
/* Prefill the deck */
|
||||
for(i=0;i<13;i++) deck[i] = deck[i+13] = i+1;
|
||||
@@ -457,8 +456,8 @@ s16 game() {
|
||||
engaged++; /* increase the amount of engaged cards */
|
||||
can_run = 0; /* Cannot run once engaged */
|
||||
|
||||
item = room[(int)ch]; /* get the item from the room */
|
||||
room[(int)ch] = 0; /* mark the room slot as empty */
|
||||
item = room[ch]; /* get the item from the room */
|
||||
room[ch] = 0; /* mark the room slot as empty */
|
||||
/* Note: We do NOT put the item back in deck. It is consumed. */
|
||||
|
||||
if(item < 14) { /* monster */
|
||||
|
||||
Reference in New Issue
Block a user