Skip to content

Instantly share code, notes, and snippets.

@dekuNukem
dekuNukem / vram_fill_test.z80
Created March 9, 2016 21:20
fills up VRAM of FAP's video card
org 0x0
start: xor d
xor e
xor b ; clear d, e, b
ld hl, 0x92c0 ; load hl with address of back of the VRAM
ld de, 2400 ; 2400 bytes of attributes
ld b, 0x1b ; color, 0x1b is 011011, should be purple
attri: ld (hl), b ; store the color into VRAM address at hl
dec hl ; decrease hl to move on to next VRAM address
@dekuNukem
dekuNukem / lotto_draw.py
Last active March 11, 2016 03:22
lotto drawing code
if lotto_underway and current_time() > next_lotto_draw:
say("Time for the lottery draw! The winning number is...")
time.sleep(2)
winning_number = random.randint(1,64)
say(str(winning_number) + "!")
time.sleep(1)
for key in lotto_user_dict:
if lotto_user_dict[key] == winning_number:
say(key.capitalize() + " won ₽2000! Congrats! PogChamp")
this_result = {'winner':key, 'payout':2000, 'winning_number':winning_number, 'timestamp':current_time()}
@dekuNukem
dekuNukem / fap_gpu_vreg.v
Created March 15, 2016 10:38
virtual register of FAP's GPU
module cpu_vreg(
input wire clk,
input wire copy_in_progress,
input wire cpu_rd,
input wire cpu_wr,
input wire cpu_mreq,
input wire [15:0] cpu_addr,
inout wire [7:0] cpu_data,
output reg back_vram_wr_low,
output reg back_vram_rd_low,
@dekuNukem
dekuNukem / helloword1.z80
Created March 15, 2016 11:05
FAP's first hello world program
org 0x0
xor d
xor e
xor b
ld sp, 0x7fff
ld hl, 0x92bf ; fill attribute RAM with 0x3c, yellow
ld de, 2400
ld b, 0x3c
clear_attri:
@dekuNukem
dekuNukem / cpu_vreg.v
Created March 15, 2016 11:29
cpu_vreg.v
module cpu_vreg(
input wire clk,
input wire copy_in_progress,
input wire close_to_vlank,
input wire cpu_rd,
input wire cpu_wr,
input wire cpu_mreq,
output reg [7:0] copy_enable,
input wire [15:0] cpu_addr,
@dekuNukem
dekuNukem / helloword2.z80
Last active March 15, 2016 11:50
FAP's second hello world program
vram_char_base_addr .equ 0x8000
vram_attri_base_addr .equ 0x8960
org 0x0
xor b
xor c
xor d
xor e
ld sp, 0x7fff
@dekuNukem
dekuNukem / kb.z80
Created March 29, 2016 14:17
keyboard interrupt demo for FAP Z80 computer
include helper.z80
org 0x0
jmp program_start
org 0x10 ; interrupt vector table
.dw 0x3000 ; keyboard interrupt at 0x3000
org 0x100
program_start:
@dekuNukem
dekuNukem / int_ctrl.c
Last active March 29, 2016 15:12
FAP's keyboard interrupt controller
int main(void)
{
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* Configure the system clock */
SystemClock_Config();
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART3_UART_Init();
@dekuNukem
dekuNukem / dump.py
Last active November 18, 2020 01:18
dekunukem's GB dumper
import serial
NINTENDO_LOGO = [206, 237, 102, 102, 204, 13, 0, 11, 3, 115, 0, 131, 0, 12, 0, 13, 0, 8, 17, 31, 136, 137, 0, 14, 220, 204, 110, 230, 221, 221, 217, 153, 187, 187, 103, 99, 110, 14, 236, 204, 221, 220, 153, 159, 187, 185, 51, 62]
gcb_flag_dict = {0x80:"GB compatible GBC game", 0xc0:"GBC only game"}
cart_type_dict = {0x00:"ROM ONLY", 0x01:"MBC1", 0x02:"MBC1+RAM", 0x03:"MBC1+RAM+BATTERY", 0x05:"MBC2", 0x06:"MBC2+BATTERY", 0x08:"ROM+RAM", 0x09:"ROM+RAM+BATTERY", 0x0B:"MMM01", 0x0C:"MMM01+RAM", 0x0D:"MMM01+RAM+BATTERY", 0x0F:"MBC3+TIMER+BATTERY", 0x10:"MBC3+TIMER+RAM+BATTERY", 0x11:"MBC3", 0x12:"MBC3+RAM", 0x13:"MBC3+RAM+BATTERY", 0x15:"MBC4", 0x16:"MBC4+RAM", 0x17:"MBC4+RAM+BATTERY", 0x19:"MBC5", 0x1A:"MBC5+RAM", 0x1B:"MBC5+RAM+BATTERY", 0x1C:"MBC5+RUMBLE", 0x1D:"MBC5+RUMBLE+RAM", 0x1E:"MBC5+RUMBLE+RAM+BATTERY", 0xFC:"POCKET CAMERA", 0xFD:"BANDAI TAMA5", 0xFE:"HuC3", 0xFF:"HuC1+RAM+BATTERY"}
ROM_size_dict = {0x00:"32KByte (no ROM banking)", 0x01:"64KByte (4 banks)", 0x02:"128KByte (8 banks)", 0x0
@dekuNukem
dekuNukem / dlatch8.v
Last active December 25, 2016 16:03
8 bit transparent latch aka 74HC573
module dlatch8(
input wire [7:0] data,
input wire LE_H,
input wire OE_L,
output reg [7:0] q
);
reg [7:0] q_internal;
// activates when LE_H or OE_L changes