Full PS1 ASM Hello World with PsyQ

This commit is contained in:
OctoSpacc 2023-11-23 12:06:00 +01:00
parent 64da9bf1df
commit 8a777d83fa
6 changed files with 153 additions and 191 deletions

4
.gitignore vendored
View File

@ -1,2 +1,6 @@
*.o
*.ps1.bin
*.exe
/PrismPs1
/saltelsasso.ps1

View File

@ -1,90 +0,0 @@
// Demonstrate DISP/DRAW env, font setup, and display a text.
// Schnappy 2020
// Based on Lameguy64 tutorial : http://lameguy64.net/svn/pstutorials/chapter1/1-display.html
#include <sys/types.h>
#include <stdio.h>
#include <libgte.h>
#include <libetc.h>
#include <libgpu.h>
#define VMODE 1 // Video Mode : 0 : NTSC, 1: PAL
#define SCREENXRES 320 // Screen width
#define SCREENYRES 240 // Screen height
#define CENTERX SCREENXRES/2 // Center of screen on x
#define CENTERY SCREENYRES/2 // Center of screen on y
#define FONTSIZE 8 * 7 // Text Field Height
//DISPENV disp[2]; // Double buffered DISPENV and DRAWENV
//DRAWENV draw[2];
extern DISPENV disp[2];
extern DRAWENV draw[2];
short db = 0; // index of which buffer is used, values 0, 1
//extern void HelloMain();
// void SetDefDispEnv1(DISPENV *disp_, int x,int y,int yy)
// {
// SetDefDispEnv(disp_, x,y, SCREENXRES,yy);
// }
// void Print12345(char c1,char c2,char c3,char c4,char c5)
// {
// char str[6];
// str[0] = c1;
// str[1] = c2;
// str[2] = c3;
// str[3] = c4;
// str[4] = c5;
// str[5] = 0;
// FntPrint(str);
// }
void c_init(void)
{
//ResetGraph(0); // Initialize drawing engine with a complete reset (0)
//SetDefDispEnv1(&disp[0]);
//SetDefDispEnv(&disp[0], 0, 0 , SCREENXRES, SCREENYRES); // Set display area for both &disp[0] and &disp[1]
//SetDefDispEnv(&disp[1], 0, SCREENYRES, SCREENXRES, SCREENYRES); // &disp[0] is on top of &disp[1]
//SetDefDrawEnv(&draw[0], 0, SCREENYRES, SCREENXRES, SCREENYRES); // Set draw for both &draw[0] and &draw[1]
//SetDefDrawEnv(&draw[1], 0, 0 , SCREENXRES, SCREENYRES); // &draw[0] is below &draw[1]
//if (VMODE) // PAL
//{
// SetVideoMode(MODE_PAL);
// disp[0].screen.y += 8; // add offset : 240 + 8 + 8 = 256
// disp[1].screen.y += 8;
//}
//SetDispMask(1); // Display on screen
setRGB0(&draw[0], 32, 32, 32); // set color for first draw area
setRGB0(&draw[1], 32, 32, 32); // set color for second draw area
draw[0].isbg = 1; // set mask for draw areas. 1 means repainting the area with the RGB color each frame
draw[1].isbg = 1;
PutDispEnv(&disp[db]); // set the disp and draw environnments
PutDrawEnv(&draw[db]);
FntLoad(960, 0); // Load font to vram at 960,0(+128)
FntOpen(32, 32, 320-32, FONTSIZE, 0, 280 ); // FntOpen(x, y, width, height, black_bg, max. nbr. chars
}
void c_display(void)
{
//DrawSync(0); // Wait for all drawing to terminate
//VSync(0); // Wait for the next vertical blank
PutDispEnv(&disp[db]); // set alternate disp and draw environnments
PutDrawEnv(&draw[db]);
db = !db; // flip db value (0 or 1)
}
//void c_print(void)
//{
//FntPrint("Testin'"); // Send string to print stream
//FntFlush(-1); // Draw printe stream
//}
//int c_main(void)
//{
// c_init(); // execute init()
// while (1) // infinite loop
// {
//c_print();
//c_display();
//HelloMain();
// }
// return 0;
//}

View File

@ -1,99 +0,0 @@
.extern c_init
.extern c_display
.extern DrawSync
.extern FntFlush
.extern FntPrint
.extern PutDispEnv
.extern PutDrawEnv
.extern ResetGraph
.extern SetDefDispEnv
.extern SetDefDrawEnv
.extern SetDispMask
.extern SetVideoMode
.extern VSync
.macro CallSetDefDispDrawEnv function,address,y
la $a0,\address
li $a1,0
li $a2,\y
li $a3,320
li $t0,240
sw $t0,16($sp)
jal \function
.endm
.macro SetBackgroundRgb address,r,g,b
# set params to items 26 27 28 of \address
.endm
.global main
main:
addi $sp,$sp,-4*6
lw $a0,0($0)
jal ResetGraph
CallSetDefDispDrawEnv SetDefDispEnv,dispEnvs+0, 0
CallSetDefDispDrawEnv SetDefDispEnv,dispEnvs+20,240
CallSetDefDispDrawEnv SetDefDrawEnv,drawEnvs+0, 240
CallSetDefDispDrawEnv SetDefDrawEnv,drawEnvs+92,0
SetBackgroundRgb drawEnvs+0, 32,32,32
SetBackgroundRgb drawEnvs+92,32,32,32
jal c_init
addi $sp,$sp,4*6
MainLoop:
#addi $sp,$sp,-4*5
jal DrawSync
jal VSync
jal c_display
la $a0,helloStr
jal FntPrint
# li $a0,70
# li $a1,71
# li $a2,72
# li $a3,73
# li $t0,120
# sw $t0,16($sp)
# jal Print12345
jal FntFlush
j MainLoop
#addi $sp,$sp,4*5
.data
helloStr:
.asciiz "Hello testin'!"
.global displayIndex
displayIndex:
.byte 0
# libgpu.h > DISPENV
.global disp
disp:
dispEnvs:
.align 2
.space 40
# libgpu.h > DRAWENV
.global draw
draw:
drawEnvs:
.align 2
.space 184

View File

@ -0,0 +1,142 @@
.extern DrawSync
.extern FntFlush
.extern FntLoad
.extern FntOpen
.extern FntPrint
.extern PutDispEnv
.extern PutDrawEnv
.extern ResetGraph
.extern SetDefDispEnv
.extern SetDefDrawEnv
.extern SetDispMask
.extern VSync
.macro FlipByteVariable address
la $t0,\address
#lb $t1,0($t0)
#beq $t1,$0,__FlipByteVariable1__
beq $t0,$0,__FlipByteVariable1__
__FlipByteVariable0__:
li $t1,0
__FlipByteVariable1__:
li $t1,1
sb $t1,($t0)
.endm
.macro CallSetDefDispDrawEnv function,address,y
la $a0,\address
li $a1,0
li $a2,\y
li $a3,320
li $t0,240
sw $t0,16($sp)
jal \function
.endm
.macro SetDisplayBackgroundRgb address,r,g,b
li $t1,\r
la $t0,\address+25
sb $t1,0($t0)
li $t1,\g
la $t0,\address+26
sb $t1,0($t0)
li $t1,\b
la $t0,\address+27
sb $t1,0($t0)
la $t0,\address+24
li $t1,1
sb $t1,0($t0)
.endm
.global main
main:
addi $sp,$sp,-4*6
lw $a0,0($0)
jal ResetGraph
CallSetDefDispDrawEnv SetDefDispEnv,dispEnvs+0, 0
CallSetDefDispDrawEnv SetDefDispEnv,dispEnvs+20,240
CallSetDefDispDrawEnv SetDefDrawEnv,drawEnvs+0, 240
CallSetDefDispDrawEnv SetDefDrawEnv,drawEnvs+92,0
SetDisplayBackgroundRgb drawEnvs+0, 32,32,32
SetDisplayBackgroundRgb drawEnvs+92,32,32,32
la $a0,dispEnvs+0
jal PutDispEnv
la $a0,drawEnvs+0
jal PutDrawEnv
li $a0,960
li $a1,0
jal FntLoad
li $a0,32
li $a1,32
li $a2,320-32
li $a3,8*7
li $t0,0
sw $t0,16($sp)
li $t1,280
sw $t1,20($sp)
jal FntOpen
addi $sp,$sp,4*6
MainLoop:
jal DrawSync
jal VSync
la $a0,dispEnvs
la $t0,displayIndex
lb $t0,($t0)
li $t1,20
mult $t0,$t1
mflo $t0
add $a0,$a0,$t0
jal PutDispEnv
la $a0,drawEnvs
la $t0,displayIndex
lb $t0,($t0)
li $t1,92
mult $t0,$t1
mflo $t0
add $a0,$a0,$t0
jal PutDrawEnv
FlipByteVariable displayIndex
la $a0,helloStr
jal FntPrint
jal FntFlush
j MainLoop
.data
helloStr:
.asciiz "Hello testin'!"
displayIndex:
.byte 0
# libgpu.h > DISPENV
dispEnvs:
.align 2
.space 2*20
# libgpu.h > DRAWENV
drawEnvs:
.align 2
.space 2*92

View File

@ -1,5 +1,5 @@
TARGET = HelloWorld
SRCS = HelloWorld2.s HelloWorld.c
SRCS = HelloWorld.s
include ../common.mk

View File

@ -10,7 +10,12 @@ Index of contents in this repo, might or might not always be complete...
I will also try to credit everyone I can for all the contents listed, when my work is in great part based on someone else's.
* Thanks to <https://github.com/PeterLemon/PSX/tree/master/Cube>:
* [BouncyCubePs1](BouncyCubePs1)
* [BouncyCubePs1.asm](BouncyCubePs1.asm)
* Thanks to <https://github.com/ABelliqueux/nolibgs_hello_worlds/tree/main/hello_world> for the original code structure; all assembly code by me:
* [HelloWorld-PS1-PsyQ.asm](HelloWorld-PS1-PsyQ.asm)
(For now there's only PSX assembly things in here, this will soon change)
## Related