• Advertisement


This topic is now archived and is closed to further replies.

The most complex piece of source code you have ever seen / written.

This topic is 5711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Surely not the most complex stuff I've written as I currently can't get to my old sources, but this one will have to do:

_addresource: movem.l d0-a6,-(sp)
clr.l (sp)
move.l a0,a2 ;ResourceTag
move.l d0,d2 ;ResourceType
move.l mrt_Code(a2),d3 ;ResourceCode
move.l a6,d7 ;Save ServerBase
syscall Forbid ;-Turn off multitasking ( 1)
move.l mrt_Type(a2),d0 ;The resource's type ( 2)
cmp.l d0,d2 ;Check if wanted type
bne.w _addresource.17 ;Not!
move.l d7,a6 ;ServerBase
cmp.l #mRTYP_LIST,d0 ;Is it a List?
beq.b _addresource.3a ;Yes
cmp.l #mRTYP_REG,d0 ;Is it a register?
beq.b _addresource.3b ;Yes
bra.w _addresource.17 ;Illegal type, quit!
_addresource.3a:lea msb_FirstList(a6),a0;Pointer to list-list ( 3)
lea msb_NumList(a6),a1;Pointer
moveq #mrl_SIZEOF,d5 ;Length of structure
bra.b _addresource.3x ;Jump
_addresource.3b:lea msb_FirstReg(a6),a0;Pointer to reg-list
lea msb_NumReg(a6),a1;Pointer
moveq #mrr_SIZEOF,d5 ;Length of structure
_addresource.3x:move.l a0,a5 ;Save it
move.l a1,d6 ;Save it
_addresource.3y:move.l (a0),d0 ;Any more?
beq.b _addresource.4 ;Not found!
move.l d0,a0 ;Copy
cmp.l mrn_Code(a0),d3 ;Is it the one?
beq.w _addresource.17 ;Yes, already present!
bra.b _addresource.3y ;Check next one
_addresource.4: cmp.b #VERSION,mrt_ServerLowVer(a2);Check version ( 4)
bhi.w _addresource.17 ;Error! To high requested!
blo.b _addresource.5 ;Not same version, dont check rev.
cmp.b #REVISION,mrt_ServerLowRev(a2);Check revision
bhi.w _addresource.17 ;Error! To high requested!
_addresource.5: move.l mrt_FunctionTable(a2),d0;FunctionTable? ( 5)
beq.w _addresource.17 ;Error! No function table!
move.l d0,a0 ;FunctionTable
moveq #-1,d0 ;Counter
move.l d0,d1 ;EndMarker
_addresource.5a:addq.l #1,d0 ;Increase counter
cmp.l (a0)+,d1 ;Check if end?
bne.b _addresource.5a ;No
move.l d0,d3 ;Save number of functions
mulu.w #6,d0 ;Size of JumpTable
move.l d0,d4 ;Save offset to base
add.l mrt_DataSize(a2),d0;-(p)Bytes ( 6)
lea msb_MemHeader0(a6),a0;-(p)MemHeader
move.l d7,a6 ;ServerBase
sbcall AllocMemNode ;-Allocate memory for jmp-table+data
tst.l d0 ;Check
beq.w _addresource.17 ;Error!
move.l d0,a3 ;Put it's mem in A3
move.l d5,d0 ;-(p)Bytes ( 7)
sbcall AllocMemNode ;-Allocate memory for structure
tst.l d0 ;Check
beq.w _addresource.22 ;Error!
move.l d0,a4 ;Put node in A4
move.l mrt_Code(a2),mrn_Code(a4); Load: Code ( 8)
move.l a3,mrn_Lower(a4); Load: Lower
add.l d4,a3 ;Get base
move.l a3,mrn_Base(a4); Load: Base
move.l a2,mrn_ResourceTag(a4); Load: ResourceTag
move.w d3,mrn_Functions(a4); Load: Functions
move.l mrt_Type(a2),mrb_Type(a3); Load: Type ( 8b)
move.l mrt_Code(a2),mrb_Code(a3); Load: Code
move.l a4,mrb_Node(a3); Load: Node
or.w #MRNF_Initialize,mrn_Flags(a4);Set initializing ( 9)
move.l a5,a0 ;-(p)FirstNodePtr
move.l a4,a1 ;-(p)ListNode
clr.l d0 ;-(p)Position
sbcall AddListNode ;-Attache it to list
move.l d6,d0 ;Pointer where to increase (10)
beq.b _addresource.11 ;None?
move.l d0,a0 ;Copy
addq.l #1,(a0) ;Increase NumberOf
_addresource.11:syscall Permit ;-Turn on multitasking (11)
move.l mrn_Base(a4),a0 ;The Base (12)
move.w mrn_Functions(a4),d0;Number of functions
subq.w #1,d0 ;Counter
bmi.b _addresource.13 ;Error!
move.l mrt_FunctionTable(a2),a1;FunctionTable
lea nof(pc),a3 ;NOFunction-Ptr
_addresource12a:move.l (a1)+,d1 ;Function
bne.b _addresource12b ;Okey
move.l a3,d1 ;NoFunction
_addresource12b:move.l d1,-(a0) ;Put Function-Address
move.w #$4EF9,-(a0) ;Put JMP-OpCode
dbra d0,_addresource12a;Loop...
_addresource.13:move.l mrn_Base(a4),a6 ;ResourceBase (13)
move.l d7,a0 ;-(p)ServerBase
jsr mRInit(a6) ;-Call Initialize-routine
tst.l d0 ;Success?
beq.b _addresource.18 ;Failed!!! (14)
or.w #MRNF_Ready,mrn_Flags(a4);Set ready-flag (15)
and.w #-1-MRNF_Initialize,mrn_Flags(a4);Clear initialize
move.l a4,(sp) ;Success/Result: mResourceNode (16)
bra.b _addresource.24 ;Done.!
_addresource.17:syscall Permit ;-Turn on multitasking (17)
bra.b _addresource.24 ;Quit!
_addresource.18:syscall Forbid ;-Turn off multitasking (18)
move.l d6,d0 ;Pointer where to decrease (19)
beq.b _addresource.20 ;None?
move.l d0,a0 ;Copy
subq.l #1,(a0) ;Decrease NumberOf
_addresource.20:move.l d7,a6 ;ServerBase (20)
move.l a4,a1 ;-(p)ListNode
sbcall RemListNode ;-Remove resource from list
lea msb_MemHeader0(a6),a0;-(p)MemHeader (21)
move.l a4,a1 ;-(p)Address
move.l mrn_Lower(a4),a3;Address to "base"
sbcall FreeMemNode ;-Free memory for structure
_addresource.22:move.l d7,a6 ;ServerBase (22)
lea msb_MemHeader0(a6),a0;-(p)MemHeader
move.l a3,a1 ;-(p)Address
sbcall FreeMemNode ;-Free memory for "base"
syscall Permit ;-Turn on multitasking (23)
_addresource.24:movem.l (sp)+,d0-a6

EDIT: PS. That was Motorola 680x0 assembly. Could also add this nice Perl statement, which is the main "loop" that parse an embedded scripting language (my own) in HTML templates, kinda nice

## Evaluate it by substituting each instance of script with the evaluation of it
$buf =~ s/
% # Start of in-line
([A-Za-z]*) # Eventual type identifier (is stored in $1). Only alpha characters!
{\s* # Expression's opening brace and white space
( # Entire expression stored in $2
( ## Match...
.*? ### Zero or more Any-characters
(\\}%)* ### Zero or more escaped closing brace
.*? ### Zero or more Any-characters
)*? ## ...zero or more times
) #
\s*}% # White space and closing brace; end of in-line
/ # Replace with...
eval {
## No specific script type, that is, BScript?
if(not $1) { return join("",&BFront::BScript::Evaluate($2, $_[2], $_[3], $_[4], 0));}
## ...is it perl then?
elsif(lc($1) eq 'perl') { return join("",eval($2)); }
## Hm, unknown type...
else { return "Unknown script type '$1'!"; }

[edited by - CWizard on August 31, 2002 5:58:24 PM]

Share this post

Link to post
Share on other sites
The most complicated code I''ve ever written is my stupid command bar control. It''s a replacement for toolbars and menus, and the code is plain aggravating >:0 Changing minor things breaks things everywhere, and a lot of the bugs depend on mouse and keyboard input, so it''s a bitch to debug on a single computer.

I''d post it here, but it''s way too big. I do plan on writing an article about it for CodeProject, but it''s just so confusing internally that I''m not sure if anyone would want to use it.

It does have a nice and simple outside interface, though :D

Since any obfuscated code will look confusing and complicated, I think we should limit this topic to functional code that wasn''t purposely obfuscated.

Share this post

Link to post
Share on other sites
Here''s the most complicated code I''ve ever written:

#include <iostream>

int main()
std::cout "Hello World!\n"

return 0;



Share this post

Link to post
Share on other sites
I wrote a particle system for java today that was pretty complicated and involved (4.48K) so I won''t include it but...

Wow, most complex piece of code I''ve ever written. Still have to do a software layer between the particles and controlling them (I want a macro-management interface so I can script it better)

Gosh, I''ve never written anything this big before that didn''t have 10^100 errors....

If programming in Perl is the closest I can come to technomancy, so be it *pouts*

Lord of the Morning.

Official Member of the Ichibanme Bakana Gaijin club.

Share this post

Link to post
Share on other sites
I have never written incredibly dilapidated, non understandable, even after 30 minutes of staring at it, type of code. Some of my code is occasionally overly long and at the same time very condensed; but never to a lack of any quick understanding of it''s purpose and eventual understanding of how it accomplishes that.

Share this post

Link to post
Share on other sites

  • Advertisement