Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2 3 ... 796

Author Topic: if self.isCoder(): post() #Programming Thread  (Read 905725 times)

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
if self.isCoder(): post() #Programming Thread
« on: January 02, 2012, 11:57:54 pm »

If you can't find it, grind it.

After tossing the idea out for this thread in the Happy Thread, I decided to make it. Have something you're programming and you want to talk about it? Go for it! Need some help with an issue? Ask, and it might get answered. Want to show off your code? We want to see it.

I swear to Armok if this thread degenerates into flaming over any of the stupid computer debates (Windows/Mac/Linux, programming languages, or anything else), I will lock it faster than a supercomputer can execute a O(0) command.

Programming Tutorials

C#

Java

C++

Common LISP

Spoiler: Virex (click to show/hide)

Perl

Spoiler: MagmaMcFry (click to show/hide)

Utilities

http://vterrain.org/

Other Noteworthy Posts

WTF JAVA, by Stargrasper
How to program while dunk, by Max White
« Last Edit: July 19, 2013, 12:25:24 am by Mego »
Logged

Darvi

  • Bay Watcher
  • <Cript> Darvi is my wifi.
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #1 on: January 03, 2012, 12:04:14 am »

Have you tried IRP yet? It's a fun esoteric programming language to work with.

Just be careful with quines, as the code will just repeat itself until the interpreters get bored.
Logged

Max White

  • Bay Watcher
  • Still not hollowed!
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #2 on: January 03, 2012, 12:04:40 am »

Oh hey, just in time. I saw Aquizzar's work over in the happy thread and thought I would also spend the evening making a roguelike. Anyway, working in c#, any way to make a window non-resizeable?

And, because sharing is caring, current three seconds work worth of code.

Code: [Select]
class Program
    {
        static void Main(string[] args)
        {
            Console.SetWindowSize(120, 41);
            Console.SetBufferSize(120, 41);

            printFrame();
            Console.ReadLine();
        }

        static void printFrame()
        {
            Console.ForegroundColor = ConsoleColor.DarkYellow;
            for (int x = 1; x < 119; x++)
            {
                Console.SetCursorPosition(x, 0);
                Console.Write("═");
                Console.SetCursorPosition(x, 39);
                Console.Write("═");
            }

            for (int y = 1; y < 39; y++)
            {
                Console.SetCursorPosition(0, y);
                Console.Write("║");
                Console.SetCursorPosition(119, y);
                Console.Write("║");
            }

            Console.SetCursorPosition(0, 0);
            Console.Write("╔");

            Console.SetCursorPosition(0, 39);
            Console.Write("╚");

            Console.SetCursorPosition(119, 0);
            Console.Write("╗");

            Console.SetCursorPosition(119, 39);
            Console.Write("╝");

            Console.ResetColor();
        }
    }

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #3 on: January 03, 2012, 12:10:29 am »

@Darvi: I've messed around with esoteric languages in the past, but I don't think IRP was one of them. Brainfuck has stuck with me, though.

@Max White: Sorry, I'm afraid I'm not much of a GUI programmer, nor a C# programmer.

TherosPherae

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #4 on: January 03, 2012, 12:17:55 am »

I've mostly just messed around in Python and MATLAB. If you need someone to bugcheck in those, I could probably help, but I've not done much in terms of actually writing code for something useful. For useless stupid shit and school assignments, yeah, but nothing truly useful :P
Logged
Quote from: Aqizzar
Being vengeance and the night could only be improved by being the ballpunching vengeful night.
Quote from: Cthulhu
Gotham's mysteriously high mental illness rate isn't so mysterious when you find out Batman thinks subduing a guy means spiking his head into the pavement like a football.

Mego

  • Bay Watcher
  • [PREFSTRING:MADNESS]
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #5 on: January 03, 2012, 12:19:56 am »

I'm mainly a C++ programmer, but I can hold my own in C, Java, and Python. I also can read semi-decently (but not write) Perl, and I dabble in Brainfuck.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #6 on: January 03, 2012, 01:06:38 am »

I kill time programming when I'm really bored.  I usually treat it as a puzzle to solve to keep myself from losing interest.  Incidentally, this is kind of my field of study.  As a consequence, I know more than a few programming languages.
Logged

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #7 on: January 03, 2012, 01:17:52 am »

Here's what I consider fun:
Code: [Select]
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Level B & 13D
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

level13D:
JSR SUB_CEILING ; force a ceiling for level 13D
level13F:
levelB:
LVLB:
REP #$20 ; 16 bit A
LDA $1462 ; layer 1 x
LSR
LSR
STA $22 ; layer 3 x
LDA $1464 ; layer 1 y
LSR
LSR
LSR
STA $24 ; layer 3 y

SEP #$20 ; 16 bit A
LDA #$19 ; set initial scanline count for HDMA gradient
SEC ; subtract the low x from 19
SBC $24 ; makes the gradient scroll with layer 3
STA $7FB400 ; rest of table is set in init

LDA $14 ; frame counter
AND #$01 ; get first bit
STA $04 ; store to scratch
ASL ; x2
CLC
ADC $04 ; plus self (so all possibilities being 0 and 3)
TAY ; stick in Y
LDA LVLB_HDMA_POINTERS,y
STA $05 ; stick these in scratch
LDA LVLB_HDMA_POINTERS+1,y
STA $06
LDA LVLB_HDMA_POINTERS+2,y
STA $07
LDA LVLB_HDMA_POINTERS+6,y
STA $08 ; stick values in scratch too
LDA LVLB_HDMA_POINTERS+7,y
STA $09
LDA LVLB_HDMA_POINTERS+8,y
STA $0A

REP #$20 ; 16 bit A
LDA #$00D5
SEC ; get initial scanline count
SBC $20
STA $00 ; store to scratch
LDA $010B ; low byte of level
CMP #$013D ; if we're in level 13D
BEQ LVLB3D ; set initial scanline count accordingly
CMP #$013F
BEQ LVLB_NO_HDMA; no HDMA (except gradient) on 13F
SEP #$20 ; 8 bit A
LDA $1F ; high byte of layer 2 x
CMP #$05 ; if 5 or above...
REP #$20 ; 16 bit A
LDA $00 ; load initial scanline count
BCS LVLB_2 ; offset accordingly. carry flag not affected by REP or LDA here
;First half of level B
CLC
ADC #$0080
LVLB_2: ; second half of level B
LVLB_CHECK_HDMA:
STA $02 ; store in scratch
CLC
ADC $24 ; add layer 3 y to it
STA $4204 ; store in division registers
LDY #$06 ; divide it by 6
STY $4206 ; these values are used MUCH later. doing it here so I don't have to waste cycles
LDA $02 ; get old value back
CMP #$0081
BCC LVLB_0 ; if <81, continue
SEC
SBC #$007F ; subtract 80 from total scanline count
AND #$007F ; max = 7F
SEP #$20 ; 8 bit A
STA [$05] ; set scanline count
LDA #$7F
LDY #$03 ; y = 3
STA [$05],y ; set second scanline count
LDA #$00 ; set HDMA pointer to beginning of table
STA $4342 ; set low byte of source
BRA LVLB_FIN
LVLB3D: ; Level 13D
CLC
ADC #$00A0
BRA LVLB_CHECK_HDMA
LVLB_NO_HDMA:
SEP #$20 ; 8 bit A
LDA #$08 ; skip HDMAing channel 4
TSB $0D9F ; set bit for channel 3
LDA #$10
TRB $0D9F ; clear for 5
RTS ; return
LVLB_0:
SEP #$20 ; 8 bit A
LDY #$03 ; y = 3
STA [$05],y ; store initial scanline count
LDA #$03 ; set HDMA pointer to second value of table
STA $4342 ; set low byte of source
LVLB_FIN:
REP #$20 ; 16 bit A
LDA $22 ; layer 3 x
STA [$08] ; set
SEP #$20 ; 8 bit A
LDA $9D ; check if game paused
BNE LVLB_TIMER_SKIP ; skip if so
LDA $14 ; frame timer
AND #$07 ; only DECREMENT timer every 8 frames
BNE LVLB_TIMER_SKIP
LDA $7EC28F ; timer
DEC A
BNE LVLB_TIMER
LDA #$06 ; reset timer at 0
STA $7EC28F
LDA $7EC290
INC A ; decrement secondary timer
CMP #$0E
BCC LVLB_TIMER2 ; if E+...
LDA #$00 ; reset to 00
LVLB_TIMER2:
STA $7EC290
BRA LVLB_TIMER_SKIP
LVLB_TIMER:
STA $7EC28F
LVLB_TIMER_SKIP:
LDA $4214 ; division quotient
STA $0C ; store to scratch
LDA $7EC28F ; division remainder
SEC
SBC $4216
BEQ LVLB_DIV4 ; if not 0...
BCS LVLB_DIV ; and not negative... continue
LVLB_DIV4:
CLC ; otherwise add 6
ADC #$06
INC $0C ; increment table offset
LVLB_DIV:
LDY #$06 ; y = 6
STA [$05],y ; set scanline count
LDA $7EC290 ; set x
CLC
ADC $0C ; add table offset
CMP #$0E ; if below E...
BCC LVLB_DIV2 ; continue
SEC ; else subtract D until it's D or below
LVLB_DIV3:
SBC #$0E
CMP #$0E
BCS LVLB_DIV3
LVLB_DIV2:
ASL A ; two byte table
CLC
ADC #$1A ; for table offset
TAX
LDY #$1A ; set y too
INC $08 ; increase pointer by 2
INC $08
REP #$20 ; 16 bit A
LVLB_LOOP: ; set values
LDA LVLB_HDMA,x ; get offset
CLC
ADC $22 ; add in layer 3 x
STA [$08],y ; set to table
DEX
DEX
DEY
DEY
BPL LVLB_LOOP

SEP #$20 ; 8 bit A

LDA $04 ; get frame number
TAX ; stick in x
LDA LVLB_HDMA_SOURCE,x
STA $4343 ; set high byte of source.

REP #$20 ; 16 bit A
LDA $02 ; total scanline count before water
CMP #$00E0
SEP #$20 ; 8 bit A
BCS LVLB_NO_HDMA_2 ; if above 00E0, skip HMDA for this frame (larger than the screen anyway)
; table needs to be set up every frame regardless, hence this check after instead of before table set up code

LDA #$18 ; channel 4, 5
TSB $0D9F ; Set HDMA channels

RTS

LVLB_NO_HDMA_2:
LDA #$08 ; skip HDMAing channel 4
TSB $0D9F ; set bit for channel 3
LDA #$10
TRB $0D9F ; clear for 5

RTS

LVLB_HDMA: ; table for HDMA effect on layer 3
db $00,$00,$FF,$FF,$FE,$FF,$FD,$FF,$FD,$FF,$FE,$FF,$FF,$FF,$00,$00,$01,$00,$02,$00,$03,$00,$03,$00,$02,$00,$01,$00 ; two copies made for efficiency
db $00,$00,$FF,$FF,$FE,$FF,$FD,$FF,$FD,$FF,$FE,$FF,$FF,$FF,$00,$00,$01,$00,$02,$00,$03,$00,$03,$00,$02,$00 ; calculates initial table offset and uses part of each table

LVLB_HDMA_POINTERS:
db $00,$B6,$7F ;frame 1, pointers + scanline count table
db $00,$B7,$7F ;frame 2
db $A0,$B6,$7F ;frame 1, values
db $A0,$B7,$7F ;frame 2

LVLB_HDMA_SOURCE:
db $B6,$B7
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #8 on: January 03, 2012, 02:39:45 am »

Here's what I consider fun:
<removed for space>

Wait, isn't that assembly?  Learning assembly not that long ago was unpleasant for me.
Logged

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #9 on: January 03, 2012, 02:45:47 am »

Eeyup.

I like it because it's extremely simple and affords a lot of control. Great for small systems, like the super nintendo (which is what that code's for). Not so great for programming anything else.
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #10 on: January 03, 2012, 02:57:10 am »

Yeah, I've had to use assembly for more complicated things before.  Probably why I'm not such a fan of it.  It does give you basically absolute control of everything, though.  It's definitely useful when efficiency is critical.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #11 on: January 03, 2012, 02:57:26 am »

Just FYI, there's a programming thread around already. People should use it more.

I've pretty much given up on developing anything meaningful in C++ by now - though it's undeniably powerful (for several reasons), I keep ending up with a bunch of obscure, nigh-unfixable bugs and a whole bunch of technical errors. It's frankly just a whole lot more trouble than it's worth.

Due to Microsoft's excellent Dreamspark program I'm now the proud owner of a suite of development software, so over the coming weeks I'll be dicking around with C# and seeing if that leads to anything.

Eeyup.

I like it because it's extremely simple and affords a lot of control. Great for small systems, like the super nintendo (which is what that code's for). Not so great for programming anything else.

I'd love to learn assembly, but I never could find a good book or tutorial on it. I don't suppose you know one?
Logged

kaijyuu

  • Bay Watcher
  • Hrm...
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #12 on: January 03, 2012, 03:11:24 am »

Well that depends on what you want to code in assembly for. Each processor has different instruction sets, and the syntax is far from universal (even for languages with the same instruction sets; my posted code would work on ~3 different SNES assemblers, but a dozen others out there would balk at various parts).


I learned SNES assembly from a half dozen different tutorials and a forum where I could ask questions. Ultimately, I'd suggest having a project in mind and asking in communities centered around it. If you wanna code your own arcade machine, for example, there are plenty of places out there that can help with making stuff for MAME. (EDIT: MAME might be bad example, since it emulates a crapload of different machines with different stuff. There's a billion different game consoles out there though that'd work though, or early computers where assembly was still used instead of higher level languages. No point in assembly if you're not either hacking something or working with something so slow a higher level language would slow things down.)
« Last Edit: January 03, 2012, 03:19:47 am by kaijyuu »
Logged
Quote from: Chesterton
For, in order that men should resist injustice, something more is necessary than that they should think injustice unpleasant. They must think injustice absurd; above all, they must think it startling. They must retain the violence of a virgin astonishment. When the pessimist looks at any infamy, it is to him, after all, only a repetition of the infamy of existence. But the optimist sees injustice as something discordant and unexpected, and it stings him into action.

Stargrasper

  • Bay Watcher
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #13 on: January 03, 2012, 03:50:04 am »

If you're serious about learning assembly, consider learning MIPS Assembly.  MARS is a fair simulator/ide for it.  It's implemented in Java, though, so that inherently slows it dramatically.  QTSPIM is also an option, though I've never used it.  MIPS is fairly commonly used today still for many hardware devices.
Logged

lordnincompoop

  • Bay Watcher
  • Allusionist
    • View Profile
Re: if self.isCoder(): post() #Programming Thread
« Reply #14 on: January 03, 2012, 03:50:07 am »

Well that depends on what you want to code in assembly for. Each processor has different instruction sets, and the syntax is far from universal (even for languages with the same instruction sets; my posted code would work on ~3 different SNES assemblers, but a dozen others out there would balk at various parts).


I learned SNES assembly from a half dozen different tutorials and a forum where I could ask questions. Ultimately, I'd suggest having a project in mind and asking in communities centered around it. If you wanna code your own arcade machine, for example, there are plenty of places out there that can help with making stuff for MAME. (EDIT: MAME might be bad example, since it emulates a crapload of different machines with different stuff. There's a billion different game consoles out there though that'd work though, or early computers where assembly was still used instead of higher level languages. No point in assembly if you're not either hacking something or working with something so slow a higher level language would slow things down.)

I was thinking x86, but alright, I'll do that.
Logged
Pages: [1] 2 3 ... 796