Created
August 9, 2011 13:47
-
-
Save micolous/1134081 to your computer and use it in GitHub Desktop.
Implementation of partyhard mode in x86_16 asm.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; A text-mode (well, 640x480 16 colours VGA graphics mode hosting 80x25 text) | |
; party hard mode in 16-bit x86 asm. Requires a vga graphics adapter that isn't | |
; fussy, as we make a mess of various things and ignore other things because we | |
; don't care and want to save space. | |
; | |
; WARNING: IF YOU SUFFER FROM EPILEPSY OR OTHER PHOTOSENSITIVITY DISORDER, DO | |
; NOT RUN THIS PROGRAM OR VIEW IT'S OUTPUT, AS IT WILL BE HARMFUL TO YOUR | |
; HEALTH. | |
; | |
; Compile with nasm -fbin partytxt.asm -o partytxt.com | |
; | |
; Michael Farrell <micolous+asm at gmail dot com>, 2010-04-06 | |
org 100h | |
; store the random seed after the palette in unallocated memory | |
%define r_seed palette + 18 | |
_start: | |
; stop ^c | |
cli | |
; set 640x480x16 colours | |
mov ax, 0012h ; ah=00h, al=12h | |
int 10h | |
;xor bl, bl | |
.loop: | |
; putparty | |
; put the text on the screen in a specific colour (bl), character by character | |
lea di, [partymsg] | |
mov ah, 0Eh | |
;xor bh, bh | |
.ploop: | |
mov al, [di] | |
int 10h | |
inc di | |
;cmp byte [di], 0 | |
cmp di, partymsg.end | |
jl .ploop | |
call random | |
;mov bx, word [random.r_seed] | |
mov bx, dx ; set a random colour, this is later used for the text colour | |
; as well | |
; set overscan colour | |
mov ax, 1001h | |
int 10h | |
jmp .loop | |
; set the rest of the pallete | |
lea si, [palette] | |
;xor dl, dl | |
.palloop: | |
call random | |
;mov ax, word [random.r_seed] | |
; make sure it's all nonzero | |
cmp dh, 0 | |
je .palloop | |
cmp dl, 0 | |
je .palloop | |
mov [si], dx ; dx in this context is still set to the value of the random | |
; number as the random function doesn't cleanup | |
inc si ; Increment the position in the palette we're writing to | |
inc si ; This takes two less bytes than `add si, 2`. | |
cmp si, palette + 16 | |
jne .palloop | |
; wait for refresh | |
mov dx,03dah | |
in al,dx | |
;test al,8 | |
cmp al, 7 | |
;jz $-3 | |
jg .loop | |
in al,dx | |
test al,8 | |
jnz .loop | |
; pallete generated, push it | |
mov ax, 1002h | |
;xor bh, bh | |
mov dx, [palette] | |
int 10h | |
jmp .loop | |
; .endloop: | |
; ; read a character again and again | |
; mov ah, 08h | |
; int 21h | |
; jmp .endloop | |
partymsg: | |
dd "PARTY HARD! " ;, 0 | |
;dd "YOU HAVE JUST LOST THE GAME! " | |
.end: | |
random: | |
; Generates a random number in dx and r_seed. Take your pick which one you | |
; want to use. | |
; | |
; Stolen from ftp://ftp.simtel.net/pub/simtelnet/msdos/asmutl/alib40.zip | |
; /alib4c.zip/random7.asm | |
; And ported to nasm, and squished a little bit because we don't care about | |
; making a big mess | |
;push dx | |
;push ax | |
mov ax, [r_seed] | |
mul word [.r_multipler] | |
;add ax, 0FFFFh ;[.r_increment] | |
dec ax ; has the same effect, right? | |
;adc dx, 0 ; Unsure what effect this has, but "add with carry" a value of | |
; 0 sounds like it does absolutely nothing. I removed it and | |
; it seems to have no effect on the randomness in this context. | |
div word [.r_permute1] | |
;xchg ax,dx | |
mov [r_seed], dx ;ax | |
;pop ax | |
;pop dx | |
ret | |
;.r_seed dw 00000h ; random number seed / random result | |
.r_permute1 dw 0FFEFh ; modulus 2^16-17 | |
.r_multipler dw 0FFD9h ; multiplier 2^16-39 | |
;.r_increment dw 0FFFFh ; increment -1 | |
palette: | |
; 18 bytes used here for the colour palette | |
; 2 bytes used after that for the random seed | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment