flat assembler
Message board for the users of flat assembler.
Index
> OS Construction > OS-like game in development, FASM MBR examples appreciated Goto page 1, 2 Next |
Author |
|
keantoken 20 Mar 2008, 17:10
Hello.
I am currently interested in developing a standalone PC game (with its own boot loader and everything). I decided I had better first focus on the boot loader. Since the documentation would take me hours to sift through, I would appreciate it if I could get some links or otherwise to MBR code written in FASM. The game isn't going to be huge, only enough space is needed for a 2D game like those found on the PS1, plus a simple physics engine and perhaps a bunch of WAVs if I can't get more MIDI-like sound formats to work. Mainly I was thinking about using the PxTone format once Pixel releases documentation. No, I don't speak japanese. But I'll find a way, don't worry. At any rate, due to the small amount of space needed, I was thinking the whole thing would run off of RAM. I imagine all that would be needed would be 256Mb IF I didn't manage to implement PxTone music format. Then again, all the requirements of this project are mainly speculation, I have never really attempted something of this sort. So the agenda for the MBR would basically be to take the information from the disk, write it to the RAM, and start things spinning (though doesn't the CPU already write everything to the RAM when it executes code?). I will be testing this with the Bochs emu on my Ubuntu Studio Linux partition. My first line of order will be to produce working line-drawing code, then circle-drawing, and gradually get more advanced until I have working include file with all the needed functions for graphical display. Please bear with me, I'm new to programming in general, no you can't dissuade me from starting out in assembly. |
|||
20 Mar 2008, 17:10 |
|
edfed 20 Mar 2008, 18:23
welcome.
programming boot video games with fasm. the boot is not the harder step as i use a simple .com loader for my tests. i code for real mode dos. then, if it works in pure dos, i adapt to pmode and vesa. the drawline function is very simple todo, just need to know how. i let you find by yourself. but for MBR with fasm look there: http://board.flatassembler.net/topic.php?t=7747 http://board.flatassembler.net/topic.php?t=7833 http://board.flatassembler.net/topic.php?t=7915 http://board.flatassembler.net/topic.php?p=73646#73646 |
|||
20 Mar 2008, 18:23 |
|
edfed 20 Mar 2008, 20:40
ouch, is it a line drawing?
does it works? what is the link with OS construcion? |
|||
20 Mar 2008, 20:40 |
|
keantoken 20 Mar 2008, 21:08
Well, I decided this was the most suitable forum because this game will essentially be an OS. Right now I'm starting at the basics: I will write up my line-drawing algorithm (I'm working on a newer one right now) and then I'll attach it to the mouse input and test it out in Bochs. I have never tested it, so I don't know if it works or not, not to mention it's not complete enough to test out yet.
I'm thinking since the code is so small I will just write it all to the boot code and test it that way. - keantoken |
|||
20 Mar 2008, 21:08 |
|
keantoken 20 Mar 2008, 21:38
Well, I'm going to bed. This is as far as I have gotten on my linedraw file. Hopefully I'll get more done tomorrow (or whatever time I wake up).
Code: ;Linedraw code written by keantoken from FASM forums. use32 start: ;starts main process Setup_Display ;initializes display via VESA 3.0 Get_Input ;Gets input. Stack values are as shown: nLines, y1, x1, y2, x2, y3, x3... ------------------------------------------------------------------------------------------- mov sp, 2 ;moves stack pointer up to x1... stack: ___1__ _2_ _3_ _4_ _5_ _6_ _7_ _8_ <- these correspond to sp numbers. pop eax ;x1 to eax... stack: nLines, y1, sb, y2, x2, y3, x3... push eax ;puts x1 back in stack: nLines, y1, sb, x1, y2, x2, y3, x3... mov sp, 4 ;move stack pointer up to x2... stack: nLines, y1, x1, y2, sb, x2, y3, x3... pop ebx ;x2 to ebx... eAx=x1 eBx=x2 stack: nLines, y1, x1, y2, y3, x3... sub eax, ebx ;x1-x2=edx, eax-ebx=eax... I believe sp changes the point at which data is extracted from the stack, for a while I though it was sb, but that's the base... - keantoken |
|||
20 Mar 2008, 21:38 |
|
edfed 20 Mar 2008, 21:49
you are crazy.
building an application with sp as a pointer is illness. the stack pointer shall not be used as this. it is very hard to code like this. how to manage large amount of data with only the sp? sp is for current stack , to save context for applications, during calls, ints, etc... if you want to play with stack, use BP as a Base Pointer and syscall coventions. SP is the Stack Pointer, not a data pointer. |
|||
20 Mar 2008, 21:49 |
|
revolution 20 Mar 2008, 21:56
You might want to consider setting the stack pointer in multiples of 4 bytes. For three reasons 1) There is a performance hit when you push/pop 32bit values to a non-32bit-aligned stack, 2) Your push/pop are using 32bit registers so you probably overwrite upper 16bit values, and the most serious 3) It is just plain ugly and difficult to follow and WON'T give you the best performance you are trying to achieve.
You have mixed 16bit and 32bit code which is also going to create a performance overhead. I wouldn't ever recommend the sort of direct manipulation of SP like you have above. It dictates too much about what direction your future code will take. I would imagine you will have many many rewrites and large headaches trying to get that type of coding style to a point of just working let alone giving good performance. BTW: When you manipulate the stack pointer in the fashion above, you have to either use protected mode ring-3 code or disable interrupts else your stack will be corrupted when the first interrupt arrives. |
|||
20 Mar 2008, 21:56 |
|
revolution 20 Mar 2008, 21:58
edfed wrote: you are crazy. |
|||
20 Mar 2008, 21:58 |
|
keantoken 21 Mar 2008, 12:44
Quote: You might want to consider setting the stack pointer in multiples of 4 bytes. For three reasons 1) There is a performance hit when you push/pop 32bit values to a non-32bit-aligned stack, 2) Your push/pop are using 32bit registers so you probably overwrite upper 16bit values, and the most serious 3) It is just plain ugly and difficult to follow and WON'T give you the best performance you are trying to achieve. Well, here it is. [quote=ASMComunity WIKI Book]There can be many stacks present at a time in memory, but there's only one current stack. Each stack is located in memory in its own segment to avoid overwriting other parts of memory. This current stack segment is pointed to by the stack segment (SS) register. The offset address to the most recently allocated stack location, called the top of the stack (TOS), is held in another register called the stack pointer (SP). The 16-bit SP register is used only in the 16-bit environment; in a 32-bit environment, the 32-bit extended stack pointer (ESP) register is used to point to the TOS. A pointer called the stack base (SB) points to the first entry that you put into the stack. Adding an entry into the stack fills the next allocatable location (lower memory address) and changes (decrements) the stack pointer (SP) to point to the that location. Removing an entry empties the current location and changes (increments) the stack pointer to point to the previous allocated location (higher memory address). * Each entry pushed into the stack makes the allocated section of the stack grow downward (toward lower memory addresses) and decreases SP by unit size. * Each entry popped out shortens the allocated section of the stack upward (toward higher memory addresses) and increments SP by unit size (4 bytes for 32-bit; 2 for 16-bit; 1 for 8-bit).[/quote] Yay for the WIKI. My basic plan is to switch stack segments via SS, for each different process in my environment. I suppose I do need to look up how interrupts work, but I don't see a page related to that on the WIKI. WIKIBooks doesn't give much info. I'm not sure why everyone is calling me crazy, this all seem to make sense to me. I know that interrupts stop the current process and then execute a handler, but about how it effects the stack, I have no idea. Any links? Oh, and in case anyone is interested, these are the notes I have compiled during the time I have been learning about assembly: Code: These notes have been compiled by keantoken from the FASM forums, do with thenm what you want. Operator Bits Bytes byte 8 1 word 16 2 dword 32 4 fword 48 6 pword 48 6 qword 64 8 tbyte 80 10 tword 80 10 dqword 128 16 ------------------------------------------------------ ________ _____ Type |Bits | --------| | |8 |al cl dl bl ah ch dh bh General |16 |ax cx dx bx sp bp si di |32 |eax ecx edx ebx esp ebp esi edi ________| | Segment |16 |es cs ss ds fs gs ________| | Control |32 |cr0 cr2 cr3 cr4 ________| | Debug |32 |dr0 dr1 dr2 dr3 dr6 dr7 ________| | FPU |80 |st0 st1 st2 st3 st4 st5 st6 st7 ________| | MMX |64 |mm0 mm1 mm2 mm3 mm4 mm5 mm6 mm7 ________| | SSE |128 |xmm0 xmm1 xmm2 xmm3 xmm4 xmm5 xmm6 xmm7 NOTES: ss, sp and esp are stack pointers:. ss switches stack segment. EAX is loaded for use with WIN32 syscalls:. eax, ecx, edx, and ebx are general-purpose registers. They are just for storing values. esi and edi are index registers, ususally used for pointers, but can be used as general registers. ------------------------------------------------------ Memory Addresses Address 0 1 2 3 4 5 6 7 Memory 2A 45 B8 20 8F CD-ROM 12 2E ------------------------------------------------------ Instrucions: mov <dest.>,<source> ;Both operands cannot be memory add <dest.>,<source> ;(dest.)=(dest.)+source sub <dest.>,<source> ;(dest.)=(dest.)-source mul <source> ;eax=(source)*eax (unsigned) imul <source> ;eax=(source)*eax (signed) div <source> ;eax=eax/(source) remainder=edx (unsigned) idiv <source> ;eax=eax/(source) remainder=edx (signed) inc <dest.> ;(dest.)=(dest.)+1 dec <dest.> ;(dest.)=(dest.)-1 push <source> ;source->stack pop <source> ;source<-stack ------------------------------------------------------ Conditions: Mnemonic Condition tested Description o OF = 1 overflow no OF = 0 not overflow c carry b CF = 1 below nae not above nor equal nc not carry Thank you for your time. - keantoken[/quote] Last edited by keantoken on 21 Mar 2008, 12:48; edited 2 times in total |
|||
21 Mar 2008, 12:44 |
|
Dex4u 21 Mar 2008, 12:46
Is your bootable game to run in realmode or pmode ? and your best start by writing a simple com or exe file to run on Dos or other such OS before moving to your bootloader, to test your functons.
Also bootprog would make a good bootloader as it can load a com or mz exe from floppy or hdd. See here: http://alexfru.chat.ru/epm.html#bootprog Ps: I have a bootable game demo if you interested. |
|||
21 Mar 2008, 12:46 |
|
revolution 21 Mar 2008, 12:48
keantoken wrote: ... <some stuff about SS> ... |
|||
21 Mar 2008, 12:48 |
|
keantoken 21 Mar 2008, 12:53
I'll get the ugly SP stuff sorted out, I think I got kinda mixed up on which registers do which. But I have the WIKI now, so everything should be fine.
Thank you Dex, I'm looking a Bootprog now and yes, I would definitely be interested in the bootable demo. Thank you for your time. - keantoken |
|||
21 Mar 2008, 12:53 |
|
Dex4u 21 Mar 2008, 16:37
Here you go (see bottom of post), its a tasm game, add to MiniDos, a small 2k dos clone i coded.
The game is set to auto load on booting, you can get MiniDos code here: http://board.flatassembler.net/topic.php?t=5275&start=0 and the game code is in the zip, along with a floppy image which you can use in a emulator or use something like winimage to put it onto a floppy.
|
|||||||||||
21 Mar 2008, 16:37 |
|
rugxulo 24 Mar 2008, 03:50
Dex, that source is to the old 1.0 version, there's actually a newer 1.1 version download (which I had always assumed you used since I "ported" it to FASM).
BTW, here's a link to Tomasz's TetrOS floppy boot sector game. |
|||
24 Mar 2008, 03:50 |
|
Dex4u 24 Mar 2008, 13:41
rugxulo wrote: Dex, that source is to the old 1.0 version, there's actually a newer 1.1 version download (which I had always assumed you used since I "ported" it to FASM). |
|||
24 Mar 2008, 13:41 |
|
rugxulo 24 Mar 2008, 21:15
EDIT: Forum bug doesn't allow apostrophes ' in attachment text.
Last edited by rugxulo on 24 Mar 2008, 21:17; edited 2 times in total |
|||
24 Mar 2008, 21:15 |
|
rugxulo 24 Mar 2008, 21:16
WHATSNEW.DOC wrote:
EDIT: invadr11.zip Last edited by rugxulo on 12 Oct 2016, 00:17; edited 1 time in total |
|||
24 Mar 2008, 21:16 |
|
itsnobody 26 Mar 2008, 13:58
keantoken wrote: Hello. Probably a lot less than 256MB, I mean look at the old Playstation 1: MIPS R3000A-compatible (R3051) 32bit RISC chip running at 33.8688 MHz Main RAM: 2 MB Video RAM: 1 MB Sound RAM: 512 KB CD-ROM Buffer: 32 KB Operating System ROM: 512 KB I doubt you'll need 256MB for any Game, and the 33MHz 3.5MB RAM Playstation ran 3D Games with sounds, etc.. What kind of game are you making? You might not even need 32-bit mode... |
|||
26 Mar 2008, 13:58 |
|
edfed 26 Mar 2008, 18:51
video ram = 1MB ==> if pixels are 32 bits leng, then, up to 256K pixels, then, 256*1000, it's more than the PS resolution, so, you can memorise more than one screen. to increase the speed. triple buffer???
sound ram = 512KB if the sound is CD quality, then, it will contain up to 6 seconds of sounds. then, see the MEGADRIVE spec, the CPU runs at 19 MHZ, the GPU is very hard to progamm cause of the sprite model, only sprites are allowed, and see the result, sonic & knuckles 3, the better game on this console. now, we have machines with 1GHz CPU, 512MB ram, and it's very slow... why??? ask it to the LAYERS constructors, as SUN, M$, BORLAND, ADOBE etc... all these layers slow down the machines. then, only one abstraction layer and directlly the asm layer will improve the performances of current machines. |
|||
26 Mar 2008, 18:51 |
|
Goto page 1, 2 Next < Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.